This commit is contained in:
Nadar
2026-03-17 13:24:22 +03:00
commit 82e5ac9d81
554 changed files with 29637 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
export interface User {
id: string
email: string
}
export default () => {
const nuxtApp = useNuxtApp()
const user = useState<User | null>('user')
const authenticated = computed(() => !!user.value)
async function getUser() {
user.value = await $api('/users/current', { method: 'GET' })
}
async function login(email: string, password: string) {
await $api('/sessions', { method: 'POST', body: { email, password } })
await getUser()
navigateTo('/projects')
}
async function register(email: string, password: string) {
await $api('/users', { method: 'POST', body: { email, password } })
navigateTo('/login')
}
async function logout() {
try {
await $api('/sessions', { method: 'delete', body: {} })
}
finally {
clearNuxtState('user')
navigateTo('/login')
}
}
async function requestResetPassword(email: string) {
await $api('/users/password_reset', { method: 'post', body: { email } })
}
async function resetPassword(newPassword: string, resetCode: string) {
await $api('/users/password_reset', {
method: 'put',
body: {
newPassword,
resetCode,
},
})
}
async function resendVerificationCode(email: string) {
await $api('/users/verification', {
method: 'put',
body: { email },
})
}
return {
user,
authenticated,
login,
register,
logout,
resendVerificationCode,
requestResetPassword,
resetPassword,
}
}