At the time of writing this Svelte-kit is still experimental but we were still able to get some
basic session auth setup by doing the following.
npm init svelte@next hello-world
Go ahead and type
Now we have a new directory that looks like the following:
For now lets create a simple file based “database” to store our sessions:
Now we want to create another
special directory for Svelte-kit, the
Inside that directory we will have the following two files:
setup/index.js file runs for each new request made to the web application.
Meaning that so long as we have the cookie with the key value
my_web_app-123 we will be able
to authenticate our user without them needing to sign in again.
To add the cookie to the users browser we can use the
Set-cookie header when returning
the login request: