Overview
The SvelteKit Auth Example is a sample implementation reference for setting up authentication using SvelteKit. It provides code examples and demonstrations of various authentication backends. This project is a work in progress and is designed to be used as a reference when building your own app.
Features
- Form actions to login and signup: Implements form actions for user login and signup.
- Store the user’s auth token in a cookie: Stores the user’s authentication token in a cookie for easy access.
- Fetch the user in the handle hook in hooks.server: Retrieves user information in the handle hook in the server-side hooks.
- Implementation of a basic session store: Includes a basic session store for managing user sessions.
- Use route (groups) to protect pages: Uses route groups to protect certain pages and restrict access to authenticated users.
- Authenticate API endpoints via an auth token: Authenticates API endpoints using an authentication token passed in the
Authorization: Bearer <TOKEN>
header. - Log out: Provides functionality for logging out the user.
Installation
To install the SvelteKit Auth Example, follow these steps:
- Make sure you have Node.js installed on your system.
- Clone the repository to your local machine.
- Navigate to the project directory in the terminal.
- Run the following commands:
npm install # Install project dependencies
npm run dev # Start the development server
- Open your web browser and access the app at
http://localhost:5000
.
Summary
The SvelteKit Auth Example is a reference implementation for adding authentication functionality to a SvelteKit app. It provides examples of various authentication backends and demonstrates how to implement features such as user login, session management, and protected routes. This project is a work in progress and serves as a guide for developers looking to add authentication to their own SvelteKit projects.