mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 20:06:57 +02:00
Admin can now toggle "OAuth-only (no password)" when creating a user. These users have no password hash and authProvider set to 'none', so they can only log in via an OAuth/SSO provider. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
26 lines
801 B
TypeScript
26 lines
801 B
TypeScript
import { json, error } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types.js';
|
|
import { requireAdmin } from '$lib/server/api-utils.js';
|
|
import { listUsers, createUser } from '$lib/server/auth.js';
|
|
|
|
export const GET: RequestHandler = async (event) => {
|
|
requireAdmin(event);
|
|
return json(listUsers());
|
|
};
|
|
|
|
export const POST: RequestHandler = async ({ request, ...event }) => {
|
|
requireAdmin(event);
|
|
const { email, displayName, password, role } = await request.json();
|
|
|
|
if (!email) {
|
|
throw error(400, 'Email is required');
|
|
}
|
|
|
|
if (password && password.length < 8) {
|
|
throw error(400, 'Password must be at least 8 characters');
|
|
}
|
|
|
|
const user = await createUser(email, displayName || email.split('@')[0], password || null, role || 'user');
|
|
return json(user, { status: 201 });
|
|
};
|