mirror of
https://github.com/ArthurDanjou/arthome.git
synced 2026-02-01 03:48:29 +01:00
Add google auth
This commit is contained in:
@@ -1,4 +1,12 @@
|
|||||||
NUXT_SESSION_PASSWORD=
|
NUXT_SESSION_PASSWORD=
|
||||||
|
|
||||||
NUXT_OAUTH_GITHUB_CLIENT_ID=
|
NUXT_OAUTH_GITHUB_CLIENT_ID=
|
||||||
NUXT_OAUTH_GITHUB_CLIENT_SECRET=
|
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=
|
NUXT_HUB_PROJECT_KEY=
|
||||||
@@ -13,29 +13,11 @@ onMounted(() => {
|
|||||||
<div class="min-h-screen flex items-center justify-center">
|
<div class="min-h-screen flex items-center justify-center">
|
||||||
<UCard class="w-full md:w-1/2">
|
<UCard class="w-full md:w-1/2">
|
||||||
<template #header>
|
<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">
|
<h1 class="font-bold text-black dark:text-white text-lg space-y-2">
|
||||||
Welcome to ArtHome
|
Welcome to ArtHome
|
||||||
</h1>
|
</h1>
|
||||||
|
</template>
|
||||||
|
<template #default>
|
||||||
<p>
|
<p>
|
||||||
ArtHome is a private platform. You need to request access to be able to use it by asking to
|
ArtHome is a private platform. You need to request access to be able to use it by asking to
|
||||||
<a
|
<a
|
||||||
@@ -45,6 +27,29 @@ onMounted(() => {
|
|||||||
target="_blank"
|
target="_blank"
|
||||||
>Arthur Danjou</a>
|
>Arthur Danjou</a>
|
||||||
</p>
|
</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">
|
<p v-if="!authorized && loggedIn" class="text-red-500 font-medium">
|
||||||
You're not authorized to access
|
You're not authorized to access
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
18
server/routes/auth/google.get.ts
Normal file
18
server/routes/auth/google.get.ts
Normal 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, '/')
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user