Skip to main content
  1. In your src directory, create a hooks.server.ts file
  1. Create a PostgreSQL table with the following columns:
  1. In your routes directory, create a route called login. In your login +page.svelte, create form elements for taking in username and password inputs. Create buttons for login and register.
    • Ensure the endpoints are set to registerValidate and loginValidate
    • Create a separate button that is set to logout endpoint
  1. In your .env file (create if you haven’t done so) that takes in your database URI and user table name
  1. After submitting the form, the user will be redirected to the endpoint of your choice.
    • Upon registering, the user will be added to the database with the username and a secure hashed password.
    • On login, the user will be authenticated through your database.
    • A browser cookie will be created as well as a session in local memory storage called “svault-auth”.
    Cookie
    • The session will have an expiration time determined in your .env file.
    • Sessions will automatically be cleaned and deleted upon expiration.
    • On logout, the user will be redirected to the home page, the cookie will be deleted from the browser, and the session will be deleted from local memory store.
And you’re good to go!