refactor(auth): cleanup auth module and streamline the registration flow
This commit is contained in:
@@ -10,6 +10,8 @@ export const useBrandingStore = defineStore(
|
||||
|
||||
const currentBrand = ref(undefined)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
const notFound = ref(false)
|
||||
|
||||
const value = useSessionStorage(
|
||||
'branding',
|
||||
@@ -30,12 +32,28 @@ export const useBrandingStore = defineStore(
|
||||
|
||||
async function updateBrand(newBrand) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
notFound.value = false
|
||||
|
||||
if (newBrand !== currentBrand.value) {
|
||||
if (newBrand !== undefined) {
|
||||
value.value = await fetchCreatorData(newBrand)
|
||||
currentBrand.value = newBrand
|
||||
presentationInfos.value = value.value?.presentationInfos
|
||||
const result = await fetchCreatorData(newBrand)
|
||||
if (result.success) {
|
||||
value.value = result.data
|
||||
currentBrand.value = newBrand
|
||||
presentationInfos.value = result.data?.presentationInfos
|
||||
} else {
|
||||
// Handle different error types
|
||||
if (result.status === 404) {
|
||||
notFound.value = true
|
||||
error.value = 'Creator not found'
|
||||
} else {
|
||||
error.value = result.error || 'Failed to load creator'
|
||||
}
|
||||
value.value = {}
|
||||
currentBrand.value = undefined
|
||||
presentationInfos.value = []
|
||||
}
|
||||
} else {
|
||||
value.value = {}
|
||||
currentBrand.value = undefined
|
||||
@@ -50,15 +68,29 @@ export const useBrandingStore = defineStore(
|
||||
try {
|
||||
const client = useClient()
|
||||
const response = await client.get(`/api/creators/@${creatorAlias}`)
|
||||
return response.data
|
||||
return { success: true, data: response.data }
|
||||
} catch (error) {
|
||||
await router.push('/');
|
||||
console.error('Error fetching creator data:', error)
|
||||
|
||||
if (error.response?.status === 404) {
|
||||
return { success: false, status: 404, error: 'Creator not found' }
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
status: error.response?.status || 500,
|
||||
error: error.message || 'Unknown error occurred'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
currentBrand,
|
||||
value,
|
||||
loading, updateBrand, presentationInfos
|
||||
loading,
|
||||
error,
|
||||
notFound,
|
||||
updateBrand,
|
||||
presentationInfos
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user