You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
523 B
TypeScript
22 lines
523 B
TypeScript
import "server-only";
|
|
import { headers } from "next/headers";
|
|
import { redirect } from "next/navigation";
|
|
import { auth } from "@/lib/auth";
|
|
|
|
export type CurrentUser = {
|
|
id: string;
|
|
name: string;
|
|
username: string | null;
|
|
};
|
|
|
|
export async function getCurrentUser(): Promise<CurrentUser> {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session) redirect("/login");
|
|
|
|
return {
|
|
id: session.user.id,
|
|
name: session.user.name,
|
|
username: session.user.username ?? null,
|
|
};
|
|
}
|