Skip to content

Commit

Permalink
feat: display message
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes committed Aug 21, 2024
1 parent a70fe1a commit e94cafe
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
54 changes: 42 additions & 12 deletions app/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts" setup>
import { useSession } from 'h3'
definePageMeta({
layout: 'centered',
middleware: 'guest',
Expand All @@ -11,20 +13,48 @@ useSeoMeta({
title,
description,
})
/**
* I'm not sure if this is the best way to handle this, but it works.
*/
const message = useState<string>('message')
if (import.meta.server) {
const session = await useSession(useRequestEvent()!, {
password: useRuntimeConfig().session.password,
})
message.value = session.data.message
await session.update({
message: '',
})
}
</script>

<template>
<UCard>
<AuthForm
:title
:description
>
Don't have an account yet? <NuxtLink
to="/register"
class="text-primary font-medium"
<div>
<UAlert
v-if="message"
class="mb-8"
color="red"
variant="outline"
:close-button="{ icon: 'i-ph-x-bold', color: 'red', variant: 'link', padded: false }"
:description="message"
@close="message = ''"
/>

<UCard>
<AuthForm
:title
:description
>
Register
</NuxtLink>
</AuthForm>
</UCard>
Don't have an account yet? <NuxtLink
to="/register"
class="text-primary font-medium"
>
Register
</NuxtLink>
</AuthForm>
</UCard>
</div>
</template>
9 changes: 7 additions & 2 deletions server/routes/auth/github.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ export default oauthGitHubEventHandler({
)

if (user) {
// Message for the user: An existing account for this email already exists. Please login and visit your profile settings to add support for Github authentication.
// See if I can access to the server with https://nuxt.com/docs/api/composables/use-request-event
await updateSession(event,
{
password: useRuntimeConfig(event).session.password,
},
{
message: 'An existing account for this email already exists. Please login and visit your profile settings to add support for GitHub authentication.',
})
return sendRedirect(event, '/login')
}

Expand Down
9 changes: 7 additions & 2 deletions server/routes/auth/twitch.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ export default oauthTwitchEventHandler({
),
)
if (user) {
// Message for the user: An existing account for this email already exists. Please login and visit your profile settings to add support for Twitch authentication.
// See if I can access to the server with https://nuxt.com/docs/api/composables/use-request-event
await updateSession(event,
{
password: useRuntimeConfig(event).session.password,
},
{
message: 'An existing account for this email already exists. Please login and visit your profile settings to add support for Twitch authentication.',
})
return sendRedirect(event, '/login')
}

Expand Down

0 comments on commit e94cafe

Please sign in to comment.