/api/auth/logout, /api/auth/refreshToken Endpoint 구현

This commit is contained in:
static
2024-12-26 17:44:44 +09:00
parent 45e214d49f
commit a42f26bab1
8 changed files with 160 additions and 51 deletions

View File

@@ -1,8 +1,27 @@
import { eq } from "drizzle-orm";
import db from "./drizzle";
import { user } from "./schema";
import { user, revokedToken } from "./schema";
export const getUserByEmail = async (email: string) => {
const users = await db.select().from(user).where(eq(user.email, email)).execute();
return users[0] ?? null;
};
export const revokeToken = async (token: string) => {
await db
.insert(revokedToken)
.values({
token,
revokedAt: Date.now(),
})
.execute();
};
export const isTokenRevoked = async (token: string) => {
const tokens = await db
.select()
.from(revokedToken)
.where(eq(revokedToken.token, token))
.execute();
return tokens.length > 0;
};