Add google auth

This commit is contained in:
2024-08-22 20:03:18 +02:00
parent 8fa15b4801
commit 331f8bd3ce
3 changed files with 51 additions and 20 deletions

View File

@@ -1,4 +1,12 @@
NUXT_SESSION_PASSWORD=
NUXT_OAUTH_GITHUB_CLIENT_ID=
NUXT_OAUTH_GITHUB_CLIENT_SECRET=
NUXT_OAUTH_GITHUB_REDIRECT_URL=
NUXT_OAUTH_GOOGLE_CLIENT_ID=
NUXT_OAUTH_GOOGLE_CLIENT_SECRET=
NUXT_OAUTH_GOOGLE_REDIRECT_URL=
NUXT_HUB_PROJECT_KEY=

View File

@@ -13,29 +13,11 @@ onMounted(() => {
<div class="min-h-screen flex items-center justify-center">
<UCard class="w-full md:w-1/2">
<template #header>
<div class="flex justify-between items-center">
<h3>Home by Arthur Danjou</h3>
<UButton
v-if="!loggedIn"
:external="true"
color="black"
icon="i-ph:github-logo-duotone"
label="Login with GitHub"
to="/auth/github"
/>
<UButton
v-if="authorized"
color="black"
icon="i-ph:house-duotone"
label="Go Home"
to="/home"
/>
</div>
</template>
<template #default>
<h1 class="font-bold text-black dark:text-white text-lg space-y-2">
Welcome to ArtHome
</h1>
</template>
<template #default>
<p>
ArtHome is a private platform. You need to request access to be able to use it by asking to
<a
@@ -45,6 +27,29 @@ onMounted(() => {
target="_blank"
>Arthur Danjou</a>
</p>
<div v-if="!loggedIn" class="flex gap-2 mt-2">
<UButton
:external="true"
color="black"
icon="i-ph:github-logo-duotone"
label="GitHub"
to="/auth/github"
/>
<UButton
:external="true"
color="red"
icon="i-ph:google-logo-duotone"
label="Google"
to="/auth/google"
/>
</div>
<UButton
v-if="authorized"
color="black"
icon="i-ph:house-duotone"
label="Go Home"
to="/home"
/>
<p v-if="!authorized && loggedIn" class="text-red-500 font-medium">
You're not authorized to access
</p>

View File

@@ -0,0 +1,18 @@
export default oauthGoogleEventHandler({
config: {
emailRequired: true,
},
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
email: user.email,
name: user.name,
},
})
return sendRedirect(event, '/home')
},
onError(event, error) {
console.error('Google OAuth error:', error)
return sendRedirect(event, '/')
},
})