refactor(auth): cleanup auth module and streamline the registration flow

This commit is contained in:
2025-06-18 21:23:33 -04:00
parent cdcfe8d7e2
commit 5a6351c537
2 changed files with 184 additions and 58 deletions

View File

@@ -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
}
})