v0.1.45 - 로그아웃 API와 세션 상태 안내 추가

This commit is contained in:
2026-04-24 10:39:42 +09:00
parent 684413a098
commit 6d4f2228cc
9 changed files with 127 additions and 9 deletions

View File

@@ -14,6 +14,10 @@ function getBearerToken(request) {
return authorization.slice('Bearer '.length).trim()
}
export function getSessionTokenFromRequest(request) {
return getBearerToken(request)
}
export async function createSession(userId) {
const token = createSessionToken()
const tokenHash = hashSessionToken(token)
@@ -68,3 +72,17 @@ export async function findAuthenticatedUser(request) {
return user ?? null
}
export async function revokeSessionByToken(token) {
if (!token) {
return false
}
const tokenHash = hashSessionToken(token)
const deletedSessions = await db
.delete(authSessions)
.where(eq(authSessions.tokenHash, tokenHash))
.returning({ id: authSessions.id })
return deletedSessions.length > 0
}