This project demonstrates how to integrate Better-Auth with a Go backend using JWT (JSON Web Tokens) for authentication. It accompanies a video tutorial by Dreams of Code.
This implementation showcases a modern authentication flow where:
- The frontend uses Better-Auth (a TypeScript authentication library) with Next.js
- The backend is built with Go and validates JWTs issued by Better-Auth
- Authentication state is shared between the Next.js app and Go API using JWT tokens
A Next.js application that implements:
- User registration and login flows using Better-Auth
- Session management with JWT tokens
- Protected routes and authentication status display
- Integration with PostgreSQL via Drizzle ORM
A Go service that:
- Validates JWT tokens issued by Better-Auth
- Implements JWKS (JSON Web Key Set) endpoint for public key distribution
- Provides protected API endpoints that require valid authentication
- Includes middleware for JWT verification and request logging
-
Authentication Flow: Users authenticate through the Next.js frontend using Better-Auth, which handles user registration, login, and session management.
-
JWT Generation: Better-Auth generates JWT tokens signed with a private key when users authenticate successfully.
-
Token Validation: The Go backend validates these JWT tokens using the public key exposed through the JWKS endpoint, ensuring requests are from authenticated users.
-
Shared Authentication: Both the Next.js app and Go API can verify the same JWT tokens, enabling seamless authentication across different services.
Check the individual README files in each project directory for specific setup instructions:
This project accompanies a tutorial video by Dreams of Code explaining the implementation details and best practices for integrating Better-Auth with Go.