generated from hutchic-org/template-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authz): setup authentication such that we have a separate logged…
… out vs logged in logic (#14) * fix(_nuxt): fix the _nuxt calls * chore(refactor): migrate app logic to index.vue * feat(secure): add a placeholder 'seure' page * feat(auth): secure the 'secure' page
- Loading branch information
Showing
6 changed files
with
62 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,4 @@ | ||
<template> | ||
<UContainer> | ||
<NuxtPwaAssets /> | ||
<UCard class="mt-10"> | ||
<UButton @click="login">Login with Google</UButton> | ||
</UCard> | ||
</UContainer> | ||
<NuxtPwaAssets /> | ||
<NuxtPage /> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useTokenClient, type AuthCodeFlowSuccessResponse, type AuthCodeFlowErrorResponse } from 'vue3-google-signin'; | ||
const handleOnSuccess = (response: AuthCodeFlowSuccessResponse) => { | ||
console.log('Access Token: ', response.access_token); | ||
// Use the access token to interact with Google Calendar API | ||
}; | ||
const handleOnError = (errorResponse: AuthCodeFlowErrorResponse) => { | ||
console.log('Error: ', errorResponse); | ||
}; | ||
const { login } = useTokenClient({ | ||
client_id: '753759858538-nufcl1qbhf9gpc7v9qs4seramd7ni2rm.apps.googleusercontent.com', | ||
scope: 'profile email https://www.googleapis.com/auth/calendar', | ||
prompt: 'consent', | ||
onSuccess: handleOnSuccess, | ||
onError: handleOnError, | ||
}); | ||
</script> |
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,13 @@ | ||
export default defineNuxtRouteMiddleware((to, from) => { | ||
if (process.server) return; | ||
|
||
const accessToken = process.client ? sessionStorage.getItem('googleAccessToken') : null; | ||
|
||
if (!accessToken && to.path !== '/') { | ||
return navigateTo('/'); | ||
} | ||
|
||
if (accessToken && to.path === '/') { | ||
return navigateTo('/secure'); | ||
} | ||
}); |
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,33 @@ | ||
<template> | ||
<UContainer> | ||
<UCard class="mt-10"> | ||
<UButton @click="login">Login with Google</UButton> | ||
</UCard> | ||
</UContainer> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useTokenClient, type AuthCodeFlowSuccessResponse, type AuthCodeFlowErrorResponse } from 'vue3-google-signin'; | ||
import { useRouter } from 'vue-router'; | ||
const router = useRouter(); | ||
const handleOnSuccess = (response: AuthCodeFlowSuccessResponse) => { | ||
console.log('Access Token: ', response.access_token); | ||
sessionStorage.setItem('googleAccessToken', response.access_token); | ||
router.push('/secure'); | ||
}; | ||
const handleOnError = (errorResponse: AuthCodeFlowErrorResponse) => { | ||
console.log('Error: ', errorResponse); | ||
}; | ||
const { login } = useTokenClient({ | ||
client_id: '753759858538-nufcl1qbhf9gpc7v9qs4seramd7ni2rm.apps.googleusercontent.com', | ||
scope: 'profile email https://www.googleapis.com/auth/calendar', | ||
prompt: 'consent', | ||
onSuccess: handleOnSuccess, | ||
onError: handleOnError, | ||
}); | ||
</script> |
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,8 @@ | ||
<template> | ||
<UContainer> | ||
<UCard class="mt-10"> | ||
<h1>Secure Page</h1> | ||
<p>All your base belong to us.</p> | ||
</UCard> | ||
</UContainer> | ||
</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