mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-05 13:20:57 +00:00
Initial commit
This commit is contained in:
46
routes/api/auth/session/+server.ts
Normal file
46
routes/api/auth/session/+server.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { validateSession, isAuthEnabled } from '$lib/server/auth';
|
||||
import { getAuthSettings } from '$lib/server/db';
|
||||
|
||||
// GET /api/auth/session - Get current session/user
|
||||
export const GET: RequestHandler = async ({ cookies }) => {
|
||||
try {
|
||||
const authEnabled = await isAuthEnabled();
|
||||
|
||||
if (!authEnabled) {
|
||||
// Auth is disabled, return anonymous session
|
||||
return json({
|
||||
authenticated: false,
|
||||
authEnabled: false
|
||||
});
|
||||
}
|
||||
|
||||
const user = await validateSession(cookies);
|
||||
|
||||
if (!user) {
|
||||
return json({
|
||||
authenticated: false,
|
||||
authEnabled: true
|
||||
});
|
||||
}
|
||||
|
||||
return json({
|
||||
authenticated: true,
|
||||
authEnabled: true,
|
||||
user: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
displayName: user.displayName,
|
||||
avatar: user.avatar,
|
||||
isAdmin: user.isAdmin,
|
||||
provider: user.provider,
|
||||
permissions: user.permissions
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Session check error:', error);
|
||||
return json({ error: 'Failed to check session' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user