Sveltekit Auth Example screenshot

Sveltekit Auth Example

Author Avatar Theme by Danawoodman
Updated: 17 Sep 2022
112 Stars

An example SvelteKit app implementing a simple authentication system.

Categories

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:

  1. Make sure you have Node.js installed on your system.
  2. Clone the repository to your local machine.
  3. Navigate to the project directory in the terminal.
  4. Run the following commands:
npm install     # Install project dependencies
npm run dev     # Start the development server
  1. 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.