Skip to content

Commit

Permalink
Let user singin and log out
Browse files Browse the repository at this point in the history
  • Loading branch information
leamsigc committed Oct 28, 2024
1 parent 43ce4a3 commit 78906e2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
28 changes: 27 additions & 1 deletion app/pages/app/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,37 @@
* @todo [ ] Integration test.
* @todo [✔] Update the typescript.
*/
import { signOut, useSession } from '~~/lib/auth-client';
const router = useRouter();
const HandleSingOut =async () => {
await signOut();
router.push('/login');
}
const { data: session,isPending,error } =await useSession(useFetch);
</script>

<template>
<div>
Dashboard page
<button class="px-5 py-3 border border-slate-400 rounded-lg" @click="HandleSingOut">
Logout
</button>


<section>
Pending: {{ isPending }}
</section>
<section>
Error: {{ error }}
</section>
<section>
User:
<code>{{ session?.user }}</code>

</section>

</div>
</template>
<style scoped></style>
52 changes: 50 additions & 2 deletions app/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts" setup>
import { signIn } from '~~/lib/auth-client';
/**
*
* Login view
Expand All @@ -10,11 +11,58 @@
* @todo [ ] Integration test.
* @todo [✔] Update the typescript.
*/
const loginForm = ref({
email: '',
password: '',
});
const loginFormSchema = [
{
$el: 'h1',
children: 'Login',
attrs: {
class: 'text-2xl font-bold mb-4',
},
},
{
$formkit: 'text',
name: 'email',
label: 'Email',
help: 'This will be used for your account.',
validation: 'required|email',
},
{
$formkit: 'password',
name: 'password',
label: 'Password',
help: 'Enter your new password.',
validation: 'required|length:5,16',
}
]
const HandleLoginUser = async () => {
await signIn.email({
email: loginForm.value.email,
password: loginForm.value.password,
callbackURL: '/app/',
fetchOptions: {
onError: (err) => console.log(err)
}
})
}
</script>

<template>
<div>
Login form here
<div class='grid place-content-center min-h-screen'>
<section class='max-w-2xl'>
<FormKit id="login-form" type="form" :actions="false" @submit="HandleLoginUser"
v-slot="{ state: { valid } }" v-model="loginForm">
<FormKitSchema :schema="loginFormSchema" />
<FormKit type="submit" label="Login" :disabled="!valid" />
</FormKit>
</section>
</div>
</template>
<style scoped></style>
1 change: 0 additions & 1 deletion app/pages/register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const registerForm = computed(() => ([
const HandleRegisterUser = async () => {
console.log(userInformation.value);
await signUp.email({
email: userInformation.value.email,
Expand Down

0 comments on commit 78906e2

Please sign in to comment.