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:
parent
2ca290d6e0
commit
600fef2b7c
11 changed files with 347 additions and 25 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue