diff --git a/frontend/composables/fetch.ts b/frontend/composables/fetch.ts index a5eed63..9bcfe07 100644 --- a/frontend/composables/fetch.ts +++ b/frontend/composables/fetch.ts @@ -3,25 +3,25 @@ import type { UseFetchOptions } from 'nuxt/app' const config = useRuntimeConfig() const useCustomFetch = async ( - path: string, - options: UseFetchOptions = {} + path: string, + options: UseFetchOptions = {} ) => { - let headers: any = {} - const token = useCookie('XSRF-TOKEN') + let headers: any = {} + const token = useCookie('XSRF-TOKEN') - if (token.value) { - headers['X-XSRF-TOKEN'] = token.value as string - } + if (token.value) { + headers['X-XSRF-TOKEN'] = token.value as string + } - return useFetch(config.public.laravelApi + path, { - credentials: 'include', - watch: false, - ...options, - headers: { - ...headers, - ...options?.headers, - }, - }) + return useFetch(config.public.laravelApi + path, { + credentials: 'include', + watch: false, + ...options, + headers: { + ...headers, + ...options?.headers, + }, + }) } export { useCustomFetch } diff --git a/frontend/composables/user.ts b/frontend/composables/user.ts index 201ae5b..26bd362 100644 --- a/frontend/composables/user.ts +++ b/frontend/composables/user.ts @@ -1,58 +1,58 @@ import { z } from 'zod' const userSchema = z.object({ - email: z.string().email(), - password: z.string().min(6), + email: z.string().email(), + password: z.string().min(6), }) const loggedInUserSchema = z.object({ - name: z.string(), + name: z.string(), }) const userLogin = async (email: String, password: String) => { - await getUser() - if (useUser().value) return + await getUser() + if (useUser().value) return - const user = userSchema.safeParse({ email, password }) + const user = userSchema.safeParse({ email, password }) - if (!user.success) return user.error.format() + if (!user.success) return user.error.format() - await useCustomFetch('/sanctum/csrf-cookie') - await useCustomFetch('/login', { method: 'POST', body: user.data }) + await useCustomFetch('/sanctum/csrf-cookie') + await useCustomFetch('/login', { method: 'POST', body: user.data }) - await getUser() + await getUser() } const newUserSchema = z.object({ - name: z.string(), - email: z.string().email(), - password: z.string().min(6), - password_confirmation: z.string().min(6), + name: z.string(), + email: z.string().email(), + password: z.string().min(6), + password_confirmation: z.string().min(6), }) const userSignup = async (data: unknown) => { - const newUser = newUserSchema.safeParse(data) + const newUser = newUserSchema.safeParse(data) - if (!newUser.success) return newUser.error.format() + if (!newUser.success) return newUser.error.format() - await useCustomFetch('/register', { method: 'POST', body: newUser.data }) + await useCustomFetch('/register', { method: 'POST', body: newUser.data }) - await getUser() + await getUser() } const getUser = async () => { - const { data, error } = await useCustomFetch('/api/user') + const { data, error } = await useCustomFetch('/api/user') - if (error.value) return + if (error.value) return - const parsed = loggedInUserSchema.safeParse(data.value) - if (!parsed.success) return - useUser().value = parsed.data.name + const parsed = loggedInUserSchema.safeParse(data.value) + if (!parsed.success) return + useUser().value = parsed.data.name } const userLogout = async () => { - await useCustomFetch('/logout', { method: 'POST' }) - useUser().value = '' + await useCustomFetch('/logout', { method: 'POST' }) + useUser().value = '' } const useUser = () => useState('user', () => '') diff --git a/frontend/composables/utils.ts b/frontend/composables/utils.ts index d3e6009..98dd157 100644 --- a/frontend/composables/utils.ts +++ b/frontend/composables/utils.ts @@ -1,5 +1,5 @@ const openUrl = (url: string) => { - window.open(url, '_blank') + window.open(url, '_blank') } export { openUrl }