organize componenst a lib

This commit is contained in:
Milo Schwartz
2024-10-13 14:50:07 -04:00
parent f7a1d20ec2
commit bdc52dcc48
9 changed files with 24 additions and 9 deletions

View File

@@ -0,0 +1,16 @@
import { GetUserResponse } from "@server/routers/user";
import { verifySession } from "./verifySession";
export async function isValidUser(): Promise<GetUserResponse | null> {
const user = await verifySession();
if (!user) {
return null;
}
if (!user.emailVerified) {
return null;
}
return user;
}

View 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;
}
}