0106bc4ea0
BREAKING CHANGE: sup config now derives entries from package.json#exports and a server/client glob instead of manual lists; module structure follows flat + barrel convention with .server.js/.client.js runtime suffixes
20 lines
665 B
JavaScript
20 lines
665 B
JavaScript
import { getSession } from '@zen/core/features/auth/actions';
|
|
import { hasPermission, PERMISSIONS } from '@zen/core/users';
|
|
import { redirect } from 'next/navigation';
|
|
|
|
export async function protectAdmin({ redirectTo = '/auth/login', forbiddenRedirect = '/' } = {}) {
|
|
const session = await getSession();
|
|
if (!session) redirect(redirectTo);
|
|
|
|
const allowed = await hasPermission(session.user.id, PERMISSIONS.ADMIN_ACCESS);
|
|
if (!allowed) redirect(forbiddenRedirect);
|
|
|
|
return session;
|
|
}
|
|
|
|
export async function isAdmin() {
|
|
const session = await getSession();
|
|
if (!session) return false;
|
|
return hasPermission(session.user.id, PERMISSIONS.ADMIN_ACCESS);
|
|
}
|