feat(platform): add Discord onboarding and Velocity gate
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { hashToken, SESSION_COOKIE_NAME } from "@minecraft-account-manager/auth";
|
||||
import { findUserBySessionToken } from "@minecraft-account-manager/database";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
import { recordAuthenticatedUiAccess } from "@/lib/audit";
|
||||
import { db } from "@/lib/database";
|
||||
|
||||
export async function getCurrentUser() {
|
||||
const token = (await cookies()).get(SESSION_COOKIE_NAME)?.value;
|
||||
if (!token) return null;
|
||||
|
||||
return findUserBySessionToken(db, hashToken(token));
|
||||
}
|
||||
|
||||
export async function requireCurrentUser(accessPath?: string) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) redirect("/?portal=1");
|
||||
if (accessPath) await recordAuthenticatedUiAccess(user, accessPath);
|
||||
return user;
|
||||
}
|
||||
Reference in New Issue
Block a user