Skip to content

Commit 5ac954b

Browse files
committed
login aas function
1 parent 8da75e8 commit 5ac954b

2 files changed

Lines changed: 54 additions & 40 deletions

File tree

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
<template>
2-
<div>
3-
<input
4-
v-model="fields.email"
5-
type="text"
6-
placeholder="Email"
7-
/>
8-
<input
9-
v-model="fields.password"
10-
type="password"
11-
placeholder="Password"
12-
/>
2+
<Form :form>
3+
<FormInput
4+
:form
5+
name="email"
6+
>
7+
<input
8+
v-model="form.fields.email"
9+
type="text"
10+
placeholder="Email"
11+
/>
12+
</FormInput>
13+
<FormInput
14+
:form
15+
name="password"
16+
>
17+
<input
18+
v-model="form.fields.password"
19+
type="password"
20+
placeholder="Password"
21+
/>
22+
</FormInput>
1323

14-
<button @click="submit()">Login</button>
15-
</div>
24+
<button>Login</button>
25+
</Form>
1626
</template>
1727

1828
<script setup lang="ts">
1929
import { useLaravelSanctum } from '#imports'
2030
2131
const { login } = useLaravelSanctum()
22-
const { fields, submit } = login
32+
const form = login()
2333
</script>

src/runtime/composables/useLaravelSanctum.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ export const useLaravelSanctum = () => {
1919
password: z.string().min(6),
2020
})
2121

22-
const login = useLaravelForm<LoginForm>({
23-
initialValues: {
24-
email: '',
25-
password: '',
26-
},
27-
submitUrl: '/login',
28-
schema: loginSchema,
29-
onSubmitSuccess: async () => {
30-
const redirectTo = config.sanctum?.redirectAuthenticated || '/'
31-
await router.push(redirectTo)
32-
},
33-
})
22+
const login = () => {
23+
return useLaravelForm<LoginForm>({
24+
initialValues: {
25+
email: '',
26+
password: '',
27+
},
28+
submitUrl: '/login',
29+
schema: loginSchema,
30+
onSubmitSuccess: async () => {
31+
const redirectTo = config.sanctum?.redirectAuthenticated || '/'
32+
await router.push(redirectTo)
33+
},
34+
})
35+
}
3436

3537
const registerSchema = z.object({
3638
name: z.string().min(1),
@@ -39,20 +41,22 @@ export const useLaravelSanctum = () => {
3941
password_confirmation: z.string().min(6),
4042
})
4143

42-
const register = useLaravelForm<RegisterRequest>({
43-
initialValues: {
44-
name: '',
45-
email: '',
46-
password: '',
47-
password_confirmation: '',
48-
},
49-
submitUrl: '/register',
50-
schema: registerSchema,
51-
onSubmitSuccess: async () => {
52-
const redirectTo = config.sanctum?.redirectAuthenticated || '/'
53-
await router.push(redirectTo)
54-
},
55-
})
44+
const register = () => {
45+
return useLaravelForm<RegisterRequest>({
46+
initialValues: {
47+
name: '',
48+
email: '',
49+
password: '',
50+
password_confirmation: '',
51+
},
52+
submitUrl: '/register',
53+
schema: registerSchema,
54+
onSubmitSuccess: async () => {
55+
const redirectTo = config.sanctum?.redirectAuthenticated || '/'
56+
await router.push(redirectTo)
57+
},
58+
})
59+
}
5660

5761
const logout = async () => {
5862
try {

0 commit comments

Comments
 (0)