feat/valid-session: check valid user/session from token instead of making a slow request to api
This commit is contained in:
18
utils/session.ts
Normal file
18
utils/session.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
export function isValidSession(session: Session | null) {
|
||||
if (!session) {
|
||||
console.log("No session available (user not authenticated).")
|
||||
return false
|
||||
}
|
||||
if (session.error) {
|
||||
console.log(`Session error: ${session.error}`)
|
||||
return false
|
||||
}
|
||||
if (session.token.expires_at && session.token?.expires_at < Date.now()) {
|
||||
console.log(`Session expired: ${session.token?.expires_at}`)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user