-
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(ui): Login and sync flow have been implemented
- Loading branch information
1 parent
bf994ca
commit 22c69fd
Showing
17 changed files
with
344 additions
and
51 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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<div id="app"> | ||
<div id="app" class="p-2"> | ||
<AppHeader /> | ||
<router-view /> | ||
</div> | ||
|
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,81 @@ | ||
<template> | ||
<div> | ||
<Toast /> | ||
|
||
<Button | ||
:disabled="loading" | ||
severity="success" | ||
label="Login with Strava" | ||
icon="pi pi-user" | ||
@click="redirectToStrava()" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Toast from 'primevue/toast'; | ||
import Button from 'primevue/button'; | ||
import { onMounted, ref } from 'vue'; | ||
import { useToast } from 'primevue/usetoast'; | ||
import { getAccessToken, getAuthorizationURL } from '@/services/auth'; | ||
import {useRoute, useRouter} from 'vue-router'; | ||
import { useUserStore } from "@/store/user"; | ||
import Cookies from "js-cookie"; | ||
export default { | ||
name: 'LoginPage', | ||
components: { | ||
Toast, | ||
Button | ||
}, | ||
setup() { | ||
const loading = ref(false); | ||
const toast = useToast(); | ||
const user = useUserStore(); | ||
const url = ref(''); | ||
const { query } = useRoute(); | ||
const router = useRouter() | ||
const login = async (code) => { | ||
const resp = await getAccessToken(code); | ||
user.setAccessToken(resp.access_token); | ||
user.setUser(resp.athlete); | ||
Cookies.set('accessToken', resp.access_token); | ||
await router.push('/'); | ||
} | ||
const fetchURL = async () => { | ||
const resp = await getAuthorizationURL(); | ||
url.value = resp.authorization_url; | ||
} | ||
onMounted(async () => { | ||
try { | ||
await fetchURL(); | ||
if (query.code) { | ||
await login(query.code); | ||
} | ||
} catch (error) { | ||
toast.add({ | ||
severity: 'error', | ||
summary: 'Error', | ||
detail: error.toString(), | ||
life: 3000, | ||
}); | ||
} | ||
}) | ||
return { | ||
loading, | ||
toast, | ||
url, | ||
user | ||
} | ||
}, | ||
methods: { | ||
redirectToStrava() { | ||
window.location.href = this.url; | ||
} | ||
} | ||
}; | ||
</script> |
Oops, something went wrong.