Skip to content

rmarscher/waku-better-auth-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Waku "Better Auth" Example

This is an example of implementing authentication in Waku using better-auth.

Install Log

npm create waku@latest
cd waku-project
npm install --save --exact better-auth better-sqlite3
npm install --save-dev --exact @types/better-sqlite3

Setup

Copy .env-example to .env and create a BETTER_AUTH_SECRET

Create auth.ts with better-auth server config.

Generate the database schema:

npm exec @better-auth/cli generate

Run the database migrations:

npm exec @better-auth/cli migrate

Create middleware for Waku to load the session from the request headers and store it in Waku's context data.

Add middleware to waku.config.ts:

import { defineConfig } from "waku/config";

export default defineConfig({
  middleware: [
    "waku/middleware/context",
    "waku/middleware/dev-server",
    "./src/middleware/auth.ts",
    "waku/middleware/handler",
  ],
});

Set up auth API routes and forward them to better-auth.

Create a better-auth client and use it in client components.

Read the session from Waku context data in server components:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages