Implement multi-step registration process: Add step indicators, error handling, and payment processing for membership registration. Enhance form validation and user feedback with success and error messages. Refactor state management for improved clarity and maintainability.
This commit is contained in:
parent
a88aa62198
commit
2ca290d6e0
22 changed files with 1994 additions and 213 deletions
48
app/composables/useAuth.js
Normal file
48
app/composables/useAuth.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
export const useAuth = () => {
|
||||
const authCookie = useCookie('auth-token')
|
||||
const memberData = useState('auth.member', () => null)
|
||||
const isAuthenticated = computed(() => !!authCookie.value)
|
||||
const isMember = computed(() => !!memberData.value)
|
||||
|
||||
const checkMemberStatus = async () => {
|
||||
if (!authCookie.value) {
|
||||
memberData.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await $fetch('/api/auth/member', {
|
||||
headers: {
|
||||
'Cookie': `auth-token=${authCookie.value}`
|
||||
}
|
||||
})
|
||||
memberData.value = response
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch member status:', error)
|
||||
memberData.value = null
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
try {
|
||||
await $fetch('/api/auth/logout', {
|
||||
method: 'POST'
|
||||
})
|
||||
authCookie.value = null
|
||||
memberData.value = null
|
||||
await navigateTo('/')
|
||||
} catch (error) {
|
||||
console.error('Logout failed:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
isAuthenticated: readonly(isAuthenticated),
|
||||
isMember: readonly(isMember),
|
||||
memberData: readonly(memberData),
|
||||
checkMemberStatus,
|
||||
logout
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue