Login watcher
This commit is contained in:
@@ -230,4 +230,12 @@ async function handleLogout() {
|
||||
await $fetch('/api/auth/logout', { method: 'POST' })
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
// Watch for authentication changes (e.g., if user is deleted)
|
||||
watch(() => authData.value?.authenticated, (newAuth, oldAuth) => {
|
||||
// If user was authenticated but now isn't (and it's not initial load)
|
||||
if (oldAuth === true && newAuth === false) {
|
||||
window.location.reload()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getAuthCookie } from '~/server/utils/auth'
|
||||
import { getAuthCookie, clearAuthCookie } from '~/server/utils/auth'
|
||||
import { getUserByUsername } from '~/server/utils/database'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
@@ -13,9 +13,18 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
const user = getUserByUsername(username)
|
||||
|
||||
// If user doesn't exist (was deleted), clear the auth cookie
|
||||
if (!user) {
|
||||
clearAuthCookie(event)
|
||||
return {
|
||||
authenticated: false,
|
||||
isAdmin: false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
authenticated: true,
|
||||
username: user?.username,
|
||||
isAdmin: user?.is_admin === 1
|
||||
username: user.username,
|
||||
isAdmin: user.is_admin === 1
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user