fix(auth): return to origin path after GitHub login
Sign-in saves the current path in sessionStorage so the OAuth callback can route back instead of always landing on Home.
This commit is contained in:
@@ -1,20 +1,34 @@
|
||||
<script lang="ts" setup>
|
||||
import { useRoute } from "vue-router"
|
||||
|
||||
import { GITHUB_OAUTH_RETURN_PATH_KEY } from "@/modules/user/service/oauthReturnPath"
|
||||
|
||||
const GITHUB_URL = "https://github.com/login/oauth/authorize"
|
||||
|
||||
const CLIENT_ID = "Iv1.12dc43d013ce3623"
|
||||
const SCOPE = "repo%20workflow"
|
||||
const REDIRECT_URI = window.location.origin
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const url = new URL(GITHUB_URL)
|
||||
url.searchParams.set("client_id", CLIENT_ID)
|
||||
url.searchParams.set("scope", SCOPE)
|
||||
url.searchParams.set("redirect_uri", REDIRECT_URI)
|
||||
|
||||
const href = url.toString()
|
||||
|
||||
const saveReturnPath = () => {
|
||||
sessionStorage.setItem(GITHUB_OAUTH_RETURN_PATH_KEY, route.fullPath)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a :href="href" class="sign-in-github btn btn-sm btn-primary">
|
||||
<a
|
||||
:href="href"
|
||||
class="sign-in-github btn btn-sm btn-primary"
|
||||
@click="saveReturnPath"
|
||||
>
|
||||
Sign in with
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
||||
Reference in New Issue
Block a user