This is the template project that's checked out and configured when you run the bando-up command from ljsthw-bandolier. This is where the code really lives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
bandolier-template/admin/bando/demos/LoggedIn.svelte.md

1.2 KiB

The LoggedIn component checks if the user is logged in by doing a GET to "/api/login" and if that API endpoint returns 401 or 403 it will perform redirects for you. It updates the $user.authenticated Svelte store (from client/stores.js) and then as your app changes that setting it will adapt and display different content.

Use this component to:

  1. Block a page's content from unauthenticated users.
  2. Redirect users to your a new location if they are not authenticated.
  3. Show a standard redirect page when it's redirecting.

In this test you are simply changing the $user.authenticated to see how the LoggedIn component handles it dynamically. You should still add a check for $user.authenticated in your own onMount since svelte will run them no matter what.

Currently you should only use LoggedIn as a major page blocking component rather than fine grained individual elements. It makes a network request to `/api/login` to confirm the user's logged in status, and if you have more than one each instance will do this check. If you see repeated calls to `/api/login` then check how your using this component on your pages.