Skip to content

Commit

Permalink
✨ well this works at least
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 13, 2024
1 parent fd118ae commit c26bef2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ useSeoMeta({
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
<modal-login />
<layout-confirm />
<u-notifications>
<template #title="{ title }">
Expand Down
8 changes: 6 additions & 2 deletions app/components/header/HeaderAuth.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
const { user } = await useUserSession()
const { user, clear } = await useUserSession()
const items = [
[
{
Expand Down Expand Up @@ -27,7 +27,11 @@ const items = [
{
label: 'Logout',
icon: 'i-mdi-logout',
click: () => useApi().logout(),
click: async () => {
clear()
useApi().fetch('/api/logout')
await navigateTo('/')
},
shortcuts: ['L'],
},
],
Expand Down
8 changes: 5 additions & 3 deletions app/components/layout/LayoutLogin.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
const emit = defineEmits(['login'])
import type { User } from '~/types/models'
const emit = defineEmits(['loggedin'])
const loading = ref(false)
interface Provider {
name: string
Expand Down Expand Up @@ -57,9 +59,9 @@ function login(name: string): void {
async function handleMessage(evt: { data: { user: User, token: string } }) {
useApi().success('logged in')
emit('login')
emit('loggedin')
await refreshNuxtData()
await navigateTo('/home')
setTimeout(async () => await navigateTo('/home'), 500)
}
function messageHandler(add: boolean): void {
Expand Down
7 changes: 6 additions & 1 deletion app/components/modal/ModalLogin.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<script setup lang="ts">
const emit = defineEmits(['loggedin'])
const { authModal } = useAuth()
const loggedin = () => {
emit('loggedin')
authModal.value = false
}
</script>

<template>
<u-modal v-model="authModal" :ui="{ width: 'w-full sm:max-w-sm' }" @close="authModal = false">
<div class="py-8 max-w-xs w-full mx-auto">
<layout-login @login="authModal = false" />
<layout-login @loggedin="loggedin" />
</div>
</u-modal>
</template>
1 change: 0 additions & 1 deletion app/components/token/TokenCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const remove = () => confirm('Delete Token', 'Are you sure you want to delete th
})
emit('reload')
success(meta.detail)
await useApi().checkUser()
})
</script>

Expand Down
7 changes: 0 additions & 7 deletions app/composables/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const useApi = () => {
alert(`Field: ${issue.path} Error: ${issue.message}`), 100 * (index + 1)),
)
}

const fetch = <T>(
url: string | (() => string),
options?: Omit<UseFetchOptions<T>, 'default'> & { default: () => T | Ref<T> },
Expand Down Expand Up @@ -50,15 +49,9 @@ export const useApi = () => {
return { fetch }
}

const logout = async () => {
await fetch('/api/logout')
await navigateTo('/')
}

return {
fetch,
setForm,
logout,
success,
}
}
6 changes: 5 additions & 1 deletion app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<script setup lang="ts">
const { authModal } = useAuth()
definePageMeta({ layout: 'bare' })
const { user } = useApi()
const { user } = useUserSession()
const detected = () => {
if (import.meta.client) document.location.href = '/home'
}
</script>

<template>
Expand All @@ -15,6 +18,7 @@ const { user } = useApi()
<u-skeleton class="w-28 h-10" />
</template>
</client-only>
<modal-login @loggedin="detected" />
</div>
</template>

Expand Down
5 changes: 5 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default defineNuxtConfig({
'@nuxt/image',
'nuxt-auth-utils',
],
runtimeConfig: {
session: {
maxAge: 60 * 60 * 24 * 365, // 1 year
},
},
eslint: {
config: {
standalone: false,
Expand Down

0 comments on commit c26bef2

Please sign in to comment.