52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { ref, computed } from 'vue'
|
|
import { defineStore } from 'pinia'
|
|
|
|
export type AuthState = 'onboarding' | 'login' | 'create' | 'recovery' | 'confirm' | 'complete'
|
|
|
|
export const useAuthStore = defineStore('auth', () => {
|
|
// State
|
|
const currentState = ref<AuthState>('onboarding')
|
|
const previousState = ref<AuthState | null>(null)
|
|
|
|
// Getters
|
|
const getCurrentState = computed(() => currentState.value)
|
|
const getPreviousState = computed(() => previousState.value)
|
|
|
|
// Actions
|
|
const setState = (state: AuthState) => {
|
|
previousState.value = currentState.value
|
|
currentState.value = state
|
|
}
|
|
|
|
const goToCreate = () => {
|
|
setState('create')
|
|
}
|
|
|
|
const goToLogin = () => {
|
|
setState('login')
|
|
}
|
|
|
|
const goToRecover = () => {
|
|
setState('recovery')
|
|
}
|
|
|
|
const goBack = () => {
|
|
if (previousState.value) {
|
|
setState(previousState.value)
|
|
} else {
|
|
setState('onboarding')
|
|
}
|
|
}
|
|
|
|
return {
|
|
currentState,
|
|
getCurrentState,
|
|
getPreviousState,
|
|
setState,
|
|
goToCreate,
|
|
goToLogin,
|
|
goToRecover,
|
|
goBack,
|
|
}
|
|
})
|