feat(api): mount better-auth (email+password + bearer) on /api/auth

This commit is contained in:
Bas van Rossem
2026-06-17 13:47:20 +02:00
parent e8aa2c67e8
commit 89f892ce0c
3 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import { describe, it, expect } from 'vitest';
import { createApp } from '../src/app';
const json = { 'content-type': 'application/json' };
describe('auth', () => {
it('signs a user up and signs them in, returning a bearer token', async () => {
const app = createApp();
const creds = { email: 'worker@example.com', password: 'sterk-wachtwoord-123', name: 'Worker' };
const signup = await app.request('/api/auth/sign-up/email', {
method: 'POST',
headers: json,
body: JSON.stringify(creds),
});
expect(signup.status).toBe(200);
const signin = await app.request('/api/auth/sign-in/email', {
method: 'POST',
headers: json,
body: JSON.stringify({ email: creds.email, password: creds.password }),
});
expect(signin.status).toBe(200);
const token = signin.headers.get('set-auth-token');
expect(token).toBeTruthy();
});
});