initial commit
This commit is contained in:
18
server/api/auth/logout.post.js
Normal file
18
server/api/auth/logout.post.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import { deleteCookie, getCookie } from 'h3'
|
||||
import { getDb } from '../../utils/db.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const sid = getCookie(event, 'session_id')
|
||||
if (sid) {
|
||||
try {
|
||||
const { run } = await getDb()
|
||||
await run('DELETE FROM sessions WHERE id = ?', [sid])
|
||||
}
|
||||
catch {
|
||||
// ignore
|
||||
}
|
||||
deleteCookie(event, 'session_id', { path: '/' })
|
||||
}
|
||||
setResponseStatus(event, 204)
|
||||
return null
|
||||
})
|
||||
Reference in New Issue
Block a user