Add authentication check and logout functionality in app.vue
This commit is contained in:
parent
ee00a8018e
commit
733a1e9f47
9 changed files with 1294 additions and 1653 deletions
21
server/api/auth/check.get.js
Normal file
21
server/api/auth/check.get.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
export default defineEventHandler(async (event) => {
|
||||
const token = getCookie(event, 'auth-token')
|
||||
|
||||
if (!token) {
|
||||
return { authenticated: false }
|
||||
}
|
||||
|
||||
const session = await useStorage('memory').getItem(`session:${token}`)
|
||||
|
||||
if (!session) {
|
||||
return { authenticated: false }
|
||||
}
|
||||
|
||||
// Check if session has expired
|
||||
if (session.expiresAt && new Date() > new Date(session.expiresAt)) {
|
||||
await useStorage('memory').removeItem(`session:${token}`)
|
||||
return { authenticated: false }
|
||||
}
|
||||
|
||||
return { authenticated: true }
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue