-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
148 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<template> | ||
<v-container> | ||
<v-row> | ||
<v-col cols="12"> | ||
<v-card> | ||
<v-card-text class="px-0 pb-0"> | ||
<alerts | ||
:success="success" | ||
success-msg="Successfully logged in!" | ||
:error="error" | ||
:error-msg="errorMsg" | ||
/> | ||
</v-card-text> | ||
</v-card> | ||
</v-col> | ||
</v-row> | ||
</v-container> | ||
</template> | ||
|
||
<script> | ||
import { mapGetters } from "vuex"; | ||
import { LOGIN } from "@/store/actions.type"; | ||
import Alerts from "@/components/Alerts.vue"; | ||
export default { | ||
name: "OAuthLogin", | ||
components: { | ||
alerts: Alerts | ||
}, | ||
data() { | ||
return { | ||
success: false, | ||
error: false, | ||
errorMsg: null, | ||
}; | ||
}, | ||
computed: { | ||
...mapGetters([ | ||
"isAuthenticated" | ||
]) | ||
}, | ||
created() { | ||
if (this.isAuthenticated) { | ||
this.$router.replace({ name: "products" }); | ||
} | ||
}, | ||
mounted() { | ||
this.detectCallback(); | ||
}, | ||
methods: { | ||
detectCallback() { | ||
const url = this.$route.query; | ||
const provider = this.$route.params.provider; | ||
const state = localStorage.getItem("oauth_state"); | ||
const code_challenge = localStorage.getItem("code_challenge"); | ||
const method = localStorage.getItem("method"); | ||
if (url.code != null && url.state != null) { | ||
if (url.state != state) { | ||
this.errorMsg = "Invalid state!"; | ||
this.error = true; | ||
this.callback = true; | ||
return; | ||
} | ||
const oauth_data_id = localStorage.getItem("oauth_data_id"); | ||
const baseUrl = window.location.href.replace("#", ""); | ||
const baseUrlOAuthId = `${baseUrl}&oauth_data_id=${oauth_data_id}`; | ||
const baseMethod = `${baseUrlOAuthId}&code_challenge_method=${method}`; | ||
const fullUrl = `${baseMethod}&code_challenge=${code_challenge}`; | ||
this.$store | ||
.dispatch(LOGIN, { | ||
type: "oauth", | ||
provider: provider, | ||
url: fullUrl | ||
}) | ||
.then(() => { | ||
this.success = true; | ||
this.error = false; | ||
const w = window.location; | ||
window.location.href = w.origin + w.pathname; | ||
}).catch(err => { | ||
this.errorMsg = `Failed to log in! ${err.message}`; | ||
this.error = true; | ||
this.$router.replace({ name: "login" }); | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
#btn-container > button { | ||
margin: 0 !important; | ||
margin-top: 10px !important; | ||
} | ||
#avatar { | ||
position: absolute; | ||
margin: 0 auto; | ||
left: 0; | ||
right: 0; | ||
top: -70px; | ||
width: 95px; | ||
height: 95px; | ||
border-radius: 50%; | ||
z-index: 9; | ||
padding: 15px; | ||
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.1); | ||
} | ||
#login-btn { | ||
font-size: 1.2em; | ||
} | ||
</style> |
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