After refreshing the page, the new Google login option disappears
P粉506963842
P粉506963842 2024-03-28 08:57:51
0
2
381

I followed the guidelines provided by Google to integrate the new Google login. I created the HTML using the code generator provided by Google.

Here I attach the complete code

<svelte:head>
    <title>Home</title>
    <meta name="description" content="Svelte demo app" />
</svelte:head>

<section>
    <div class="h-screen">
        <div
            id="g_id_onload"
            data-client_id="534101779287-bm07dc8v4ln4kulqbql61nsglcku74vg.apps.googleusercontent.com"
            data-context="use"
            data-ux_mode="redirect"
            data-login_uri="http://localhost:5173/auth/callback"
        />
        <div class="bg-red-300 h-80">
            <div
                class="g_id_signin"
                data-type="standard"
                data-shape="rectangular"
                data-theme="outline"
                data-text="signin_with"
                data-size="medium"
                data-logo_alignment="left"
                data-width="180"
            />
        </div>
    </div>
</section>

It works great the first time the page is rendered.

When we refresh the page using Command R or click the reload icon in the browser, the login button disappears.

P粉506963842
P粉506963842

reply all(2)
P粉018548441

Now I created the component using Javascript and here I added the answer.

I declared google as a global variable in app.d.ts

// See https://kit.svelte.dev/docs/types#app
    // for information about these interfaces
    declare global {
        const google: any;
        namespace App {
        }
    }
export {};
I created a svelte file to create the svelte component for the login button

let canvas: any; //Created a variable to optain a reference to rendered div element
    
P粉696146205

When using SvelteKit, hard reloading is rendered server-side. The code might be incompatible with this or be executed in the wrong order.

Check the console for errors and move the code that must run on the client to onMount. You can also use ssr Page Options Turn off server-side rendering for specific pages as a last resort.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!