@fernando.mema/sv-better-auth-prisma
v0.1.1
Published
<a id="readme-top"></a>
Downloads
296
Maintainers
Readme
View Better Auth Docs · Report Bug · Request Feature
About
This addon sets up Better Auth in your SvelteKit project with:
- Better Auth server configuration with Prisma adapter
- SvelteKit hooks for session management
- Admin plugin with role-based access control
- Email & password authentication
- Optional GitHub OAuth demo
- Demo pages for login/logout flow
Requires: @fernandomema/sv-prisma (or manual Prisma setup)
Installation
npx sv add @fernandomema/sv-better-auth-prismaOptions
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| admin | boolean | true | Include the Better Auth admin plugin |
| demo | multiselect | ['password'] | Demo pages to include: Email & Password, GitHub OAuth |
What It Does
Files Created
| File | Purpose |
|------|---------|
| src/lib/server/auth.ts | Better Auth server configuration |
| src/lib/server/db/auth.schema.ts | Auth schema placeholder |
| src/routes/demo/better-auth/+page.svelte | Demo page (if selected) |
| src/routes/demo/better-auth/login/+page.svelte | Login demo page (if selected) |
Files Modified
| File | Changes |
|------|---------|
| .env | Adds ORIGIN, BETTER_AUTH_SECRET, GITHUB_* vars |
| .env.example | Adds environment variable templates |
| src/app.d.ts | Adds User and Session types to App.Locals |
| src/hooks.server.ts | Adds Better Auth session handler |
| package.json | Adds auth:schema script |
Environment Variables
| Variable | Description |
|----------|-------------|
| ORIGIN | The app origin (base URL), e.g. http://localhost:5173 |
| BETTER_AUTH_SECRET | Secret for signing tokens (32+ chars for production) |
| GITHUB_CLIENT_ID | GitHub OAuth client ID (if GitHub demo selected) |
| GITHUB_CLIENT_SECRET | GitHub OAuth client secret (if GitHub demo selected) |
Next Steps
After installation:
- Run
npm run auth:schemato generate the auth schema - Run
npm run db:pushto update your database - Check
ORIGIN&BETTER_AUTH_SECRETin.env - If using GitHub OAuth, set
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETin.env - Visit
/demo/better-authroute to view the demo (if selected)
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt for more information.
Contact
Fernando - @fernandomema
Project Link: https://github.com/fernandomema/sv-addons
Acknowledgments
- Better Auth - Authentication framework
- Prisma - Database ORM
- Svelte CLI - Official Svelte tooling
- Best README Template - README template
