<scriptlang="ts">import{Collapse,Navbar,NavbarToggler,NavbarBrand,Nav,NavItem,NavLink,}from'sveltestrap/src';// variable that control whether mobile menu is open or closedletisOpen=false;</script><Navbarcolor="light"lightexpand="md"><NavbarBrandhref="/">Recipe Site</NavbarBrand><NavbarToggleron:click={()=> (isOpen = !isOpen)} />
<Collapse{isOpen}navbarexpand="md"on:update="{handleUpdate}"><Navclass="ms-auto"navbar><NavItem><NavLinkhref="/login">Login</NavLink></NavItem><NavItem><NavLink>Logout</NavLink></NavItem></Nav></Collapse></Navbar>
4. Add logic to dynamically display the login and logout
<scriptlang="ts">import{Collapse,Navbar,NavbarToggler,NavbarBrand,Nav,NavItem,NavLink,}from'sveltestrap/src';importauthStorefrom'../stores/authStore';// variable that control whether mobile menu is open or closedletisOpen=false;</script><Navbarcolor="light"lightexpand="md"><NavbarBrandhref="/">Recipe Site</NavbarBrand><NavbarToggleron:click={()=> (isOpen = !isOpen)} />
<Collapse{isOpen}navbarexpand="md"><Navclass="ms-auto"navbar> {#if $authStore.firebaseControlled}
{#if !$authStore.isLoggedIn}
<NavItem><NavLinkhref="/login">Login</NavLink></NavItem> {:else}
<NavItem><NavLink>Logout</NavLink></NavItem> {/if}
{/if}
</Nav></Collapse></Navbar>
<scriptlang="ts">import{Collapse,Navbar,NavbarToggler,NavbarBrand,Nav,NavItem,NavLink,}from'sveltestrap/src';importauthStorefrom'../stores/authStore';importfirebasefrom'firebase/app';// variable that control whether mobile menu is open or closedletisOpen=false;// handles the logout ofasyncfunctionlogout(){awaitfirebase.auth().signOut();}</script><Navbarcolor="light"lightexpand="md"><NavbarBrandhref="/">Recipe Site</NavbarBrand><NavbarToggleron:click={()=> (isOpen = !isOpen)} />
<Collapse{isOpen}navbarexpand="md"><Navclass="ms-auto"navbar>
{#if $authStore.firebaseControlled}
{#if !$authStore.isLoggedIn}
<NavItem><NavLinkhref="/login">Login</NavLink></NavItem>
{:else}
<NavItem><NavLinkon:click={logout}>Logout</NavLink></NavItem>
{/if}
{/if}
</Nav></Collapse></Navbar>
<scriptlang="ts">import{Row,Col}from'sveltestrap';importfirebasefrom'firebase/app';importauthStorefrom'../stores/authStore';import{goto}from'$app/navigation';import{onDestroy}from'svelte';asyncfunctionloginWithGoogle(){try{constprovider=newfirebase.auth.GoogleAuthProvider();awaitfirebase.auth().signInWithPopup(provider);}catch(e){console.log(e);}}authStore.subscribe(async(info)=>{if(info.isLoggedIn){try{awaitgoto('/');}catch(e){console.log(e)}}});</script><Row><Col><h1>Login with Google</h1></Col></Row><Row><Col><imgon:click={loginWithGoogle}src="/login-with-google.png"alt="Login With Google"/></Col></Row><style>img{cursor:pointer;}</style>
<scriptlang="ts">import{Row,Col}from'sveltestrap';importfirebasefrom'firebase/app';importauthStorefrom'../stores/authStore';import{goto}from'$app/navigation';import{onDestroy}from'svelte';asyncfunctionloginWithGoogle(){try{constprovider=newfirebase.auth.GoogleAuthProvider();awaitfirebase.auth().signInWithPopup(provider);}catch(e){console.log(e);}}constsub=authStore.subscribe(async(info)=>{if(info.isLoggedIn){try{awaitgoto('/');}catch(e){console.log(e)}}});onDestroy(()=>{sub();});</script><Row><Col><h1>Login with Google</h1></Col></Row><Row><Col><imgon:click={loginWithGoogle}src="/login-with-google.png"alt="Login With Google"/></Col></Row><style>img{cursor:pointer;}</style>
8. Cleanup index.svelte file
123456789
<scriptlang="ts">import{Row,Col,Button}from'sveltestrap';</script><Row><Col><h1>Welcome to the recipe site</h1></Col></Row>