mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-14 08:56:39 +00:00
organize componenst a lib
This commit is contained in:
23
src/lib/auth/verifySession.ts
Normal file
23
src/lib/auth/verifySession.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { internal } from "@app/api";
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function verifySession(): Promise<GetUserResponse | null> {
|
||||
const sessionId = cookies().get("session")?.value ?? null;
|
||||
|
||||
try {
|
||||
const res = await internal.get<AxiosResponse<GetUserResponse>>(
|
||||
"/user",
|
||||
{
|
||||
headers: {
|
||||
Cookie: `session=${sessionId}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return res.data.data;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user