- In your
srcdirectory, create ahooks.server.tsfile
- Create a PostgreSQL table with the following columns:
- In your
routesdirectory, create a route calledlogin. 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
registerValidateandloginValidate - Create a separate button that is set to
logoutendpoint
- Ensure the endpoints are set to
- In your
.envfile (create if you haven’t done so) that takes in your database URI and user table name
-
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”.
- The session will have an expiration time determined in your
.envfile. - 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!
