mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-24 20:55:04 +02:00
setup server admin
This commit is contained in:
parent
e0b1aa98e0
commit
4a1e869e58
29 changed files with 409 additions and 251 deletions
42
server/auth/checkValidInvite.ts
Normal file
42
server/auth/checkValidInvite.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import db from "@server/db";
|
||||
import { UserInvite, userInvites } from "@server/db/schema";
|
||||
import { isWithinExpirationDate } from "oslo";
|
||||
import { verifyPassword } from "./password";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export async function checkValidInvite({
|
||||
inviteId,
|
||||
token
|
||||
}: {
|
||||
inviteId: string;
|
||||
token: string;
|
||||
}): Promise<{ error?: string; existingInvite?: UserInvite }> {
|
||||
const existingInvite = await db
|
||||
.select()
|
||||
.from(userInvites)
|
||||
.where(eq(userInvites.inviteId, inviteId))
|
||||
.limit(1);
|
||||
|
||||
if (!existingInvite.length) {
|
||||
return {
|
||||
error: "Invite ID or token is invalid"
|
||||
};
|
||||
}
|
||||
|
||||
if (!isWithinExpirationDate(new Date(existingInvite[0].expiresAt))) {
|
||||
return {
|
||||
error: "Invite has expired"
|
||||
};
|
||||
}
|
||||
|
||||
const validToken = await verifyPassword(token, existingInvite[0].tokenHash);
|
||||
if (!validToken) {
|
||||
return {
|
||||
error: "Invite ID or token is invalid"
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
existingInvite: existingInvite[0]
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue