Feat/GitHub auth (#6)

*  (sign in) create sign in to github button

*  (github login) login via github button

* 💄 (homepage)

*  (date fns)

*  (github login) refresh token when token expired
This commit is contained in:
Julien Calixte
2021-05-01 23:35:38 +02:00
committed by GitHub
parent f934562834
commit 0e52b16b1b
12 changed files with 259 additions and 34 deletions

View File

@@ -0,0 +1,56 @@
<template>
<div class="authorize">
<div v-if="hasError">An error occured when sign in...</div>
</div>
</template>
<script lang="ts">
import { GithubToken } from '@/modules/user/interfaces/GithubToken'
import { GithubTokenError } from '@/modules/user/interfaces/GithubTokenError'
import { useGitHubLogin } from '@/hooks/useGitHubLogin.hook'
import { defineComponent, onBeforeMount, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
const AUTHENTICATION_SERVER = 'https://litenote.li212.fr'
export default defineComponent({
name: 'Authorize',
setup() {
const route = useRoute()
const router = useRouter()
const { saveCredentials } = useGitHubLogin()
const code = route.query.code
let hasError = ref(false)
onBeforeMount(async () => {
if (code) {
const authenticationServerURL = new URL(AUTHENTICATION_SERVER)
authenticationServerURL.searchParams.set('code', code.toString())
const response = await fetch(authenticationServerURL.toString())
const body = (await response.json()) as GithubToken | GithubTokenError
if ('error' in body) {
hasError.value = true
} else {
body.access_token
saveCredentials(body)
}
router.push({ name: 'Home' })
}
})
return {
code,
hasError
}
}
})
</script>
<style scoped lang="scss">
.authorize {
}
</style>