Skip to content

SvelteKit - Login/Logout in a Navbar component #447

Answered by pilcrowonpaper
jordanrwm asked this question in Help
Discussion options

You must be logged in to vote

You can get the current session in +layout/page.server.ts and pass it to your nav bar.

It seems you can't handle form actions inside +layout.server.ts. If you want to have the logout button inside the nabber, you may be able to create /logout/+page.server.ts and export actions that handle sign out there. Then, you can create a form with use:action where action="/logout" inside the nav bar. This will make sure the logout button works for both JS and non-JS users.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jordanrwm
Comment options

@pilcrowonpaper
Comment options

@jordanrwm
Comment options

Answer selected by pilcrowonpaper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants