mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-24 13:56:39 +00:00
improve verify email redirect flow
This commit is contained in:
@@ -3,15 +3,33 @@ import { authCookieHeader } from "@app/api/cookies";
|
||||
import { GetUserResponse } from "@server/routers/user";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
||||
export async function verifySession(): Promise<GetUserResponse | null> {
|
||||
export async function verifySession({
|
||||
skipCheckVerifyEmail,
|
||||
}: {
|
||||
skipCheckVerifyEmail?: boolean;
|
||||
} = {}): Promise<GetUserResponse | null> {
|
||||
try {
|
||||
const res = await internal.get<AxiosResponse<GetUserResponse>>(
|
||||
"/user",
|
||||
await authCookieHeader()
|
||||
await authCookieHeader(),
|
||||
);
|
||||
|
||||
return res.data.data;
|
||||
} catch {
|
||||
const user = res.data.data;
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (
|
||||
!skipCheckVerifyEmail &&
|
||||
!user.emailVerified &&
|
||||
process.env.FLAGS_EMAIL_VERIFICATION_REQUIRED == "true"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user