Authjs Sveltekit Cloudflare Pages screenshot

Authjs Sveltekit Cloudflare Pages

Author Avatar Theme by Jschlesser
Updated: 15 Mar 2023
24 Stars

A demo of using authjs with sveltekit and cloudflare pages

Categories

Overview

This repository is a demo for building an AuthJS.dev authenticated site with SvelteKit and deployment on Cloudflare Pages using a D1(Alpha) database adapter for the authjs.dev user and session store. It demonstrates this using a GitHub OAuth application as the authentication provider.

Features

  • Building an authenticated site with SvelteKit
  • Deployment on Cloudflare Pages
  • Usage of D1(Alpha) database adapter for user and session store
  • GitHub OAuth authentication integration
  • Demostration of AuthJS.dev

Installation

  1. Clone or Fork and Clone this project to your local machine.
  2. Create a GitHub OAuth App for local development. Use the following details:
    • Homepage Url: http://127.0.0.1:8788
    • Authorization Callback URL: http://127.0.0.1:8788/auth/callback/github
    • Generate a secret and keep it and the client id somewhere temporarily, you will need it in the next steps
    • Click Register and then click Update Application
  3. Rename the .dev.vars.example file to .dev.vars.
  4. Fill in the client id and secret from the previous step in your .dev.vars file. This file is in .gitignore.
  5. Follow the instructions in the file to generate an AUTH_SECRET.
  6. Test locally by running the following commands in your terminal:
    • npm install
    • npm run build
    • npm run wrangle
  7. In a separate terminal session, run npx vite build -w to have vite auto build when it sees source changes.
  8. Open a browser to http://127.0.0.1:8788 or whatever port shows up in the terminal output from npm run wrangle.

Summary

This repository provides a demo of building an AuthJS.dev authenticated site with SvelteKit and deploying it on Cloudflare Pages using a D1(Alpha) database adapter for the AuthJS.dev user and session store. It includes integration with GitHub OAuth for authentication. The installation guide provides step-by-step instructions on setting up the project for local development and testing.