Enhance authentication flow: Add authentication-based buttons in AppNavigation for logged-in users, improve member status checks in useAuth, and update join page to automatically redirect to the dashboard after registration. Adjust cookie settings for better development experience.

This commit is contained in:
Jennie Robinson Faber 2025-09-03 16:55:01 +01:00
parent 2ca290d6e0
commit 600fef2b7c
11 changed files with 347 additions and 25 deletions

View file

@ -1,26 +1,25 @@
export const useAuth = () => {
const authCookie = useCookie('auth-token')
const memberData = useState('auth.member', () => null)
const isAuthenticated = computed(() => !!authCookie.value)
const isAuthenticated = computed(() => !!memberData.value)
const isMember = computed(() => !!memberData.value)
const checkMemberStatus = async () => {
if (!authCookie.value) {
memberData.value = null
return false
}
console.log('🔍 checkMemberStatus called')
console.log(' - Current memberData:', !!memberData.value)
try {
const response = await $fetch('/api/auth/member', {
headers: {
'Cookie': `auth-token=${authCookie.value}`
}
})
console.log(' - Making API call to /api/auth/member...')
const response = await $fetch('/api/auth/member')
console.log(' - API response received:', { email: response.email, id: response.id })
memberData.value = response
console.log(' - ✅ Member authenticated successfully')
return true
} catch (error) {
console.error('Failed to fetch member status:', error)
console.error(' - ❌ Failed to fetch member status:', error.statusCode, error.statusMessage)
memberData.value = null
console.log(' - Cleared memberData')
return false
}
}
@ -30,7 +29,6 @@ export const useAuth = () => {
await $fetch('/api/auth/logout', {
method: 'POST'
})
authCookie.value = null
memberData.value = null
await navigateTo('/')
} catch (error) {