-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
853f110
commit cbea8c9
Showing
17 changed files
with
909 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script setup lang="ts"> | ||
const { signOut, data, status } = useAuth() | ||
const onClickSignOut = async () => { | ||
await signOut({ callbackUrl: '/' }) | ||
} | ||
const items = [ | ||
[{ | ||
label: 'Sign Out', | ||
icon: 'i-heroicons-arrow-right-start-on-rectangle-16-solid', | ||
click: async () => { | ||
await onClickSignOut() | ||
} | ||
}] | ||
] | ||
const buttonColor = computed(() => { | ||
return data?.value?.role === 'superadmin' ? 'red' : 'white' | ||
}) | ||
</script> | ||
<template> | ||
<ClientOnly> | ||
<div> | ||
<UButton | ||
icon="i-heroicons-user-circle-16-solid" | ||
to="/login" | ||
variant="outline" | ||
v-if="status === 'unauthenticated'">Log In</UButton> | ||
<div v-else> | ||
<UDropdown :items="items" :popper="{ placement: 'bottom-end' }"> | ||
<UButton :color="buttonColor" :label="data?.name" trailing-icon="i-heroicons-chevron-down-20-solid" /> | ||
</UDropdown> | ||
</div> | ||
</div> | ||
</ClientOnly> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script setup lang="ts"> | ||
import { object, string, type InferType } from 'yup' | ||
definePageMeta({ | ||
auth: { | ||
unauthenticatedOnly: true, | ||
navigateAuthenticatedTo: '/' | ||
} | ||
}) | ||
const { signIn } = useAuth() | ||
const loading = ref(false) | ||
const toast = useToast() | ||
const schema = object({ | ||
name: string().min(1).required('Required'), | ||
password: string().min(8, 'Must be at least 8 characters').required('Required') | ||
}) | ||
type Schema = InferType<typeof schema> | ||
const state = reactive({ | ||
name: undefined, | ||
password: undefined | ||
}) | ||
async function onSubmit() { | ||
loading.value = true | ||
try { | ||
await signIn({ | ||
username: state.name, | ||
password: state.password | ||
}, { | ||
callbackUrl: '/' | ||
}) | ||
} catch (error) { | ||
toast.add({ | ||
title: 'Failed to log in', | ||
description: error.statusMessage, | ||
color: 'red' | ||
}) | ||
} | ||
loading.value = false | ||
} | ||
</script> | ||
<template> | ||
<ClientOnly> | ||
<UCard class="w-[400px] mx-auto"> | ||
<template #header> | ||
<h1>Log in</h1> | ||
</template> | ||
|
||
<UForm :schema="schema" :state="state" class="space-y-4" @submit="onSubmit"> | ||
<UFormGroup label="Name" name="name"> | ||
<UInput v-model="state.name" /> | ||
</UFormGroup> | ||
|
||
<UFormGroup label="Password" name="password"> | ||
<UInput v-model="state.password" type="password" /> | ||
</UFormGroup> | ||
|
||
<UButton type="submit" :loading="loading"> | ||
Continue | ||
</UButton> | ||
</UForm> | ||
</UCard> | ||
</ClientOnly> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
const { signOut } = useAuth() | ||
</script> | ||
<template> | ||
<ClientOnly> | ||
<div> | ||
<p>Sign Out</p> | ||
<button @click="signOut">Sign Out</button> | ||
</div> | ||
</ClientOnly> | ||
</template> |
Oops, something went wrong.