0
0
Fork 0

Pass redirect URI from the App component rather than only having access to it in the login view.

This commit is contained in:
Tyler-A 2020-08-05 20:51:25 -06:00
parent 7776ae80f0
commit b76cb8070a
4 changed files with 26 additions and 9 deletions

View file

@ -1,8 +1,9 @@
<template> <template>
<div class="maximize_size"> <div class="maximize_size">
<LoginCard v-if="!is_authed" /> <LoginCard v-if="!is_authed" :redirect="auth.redirect" />
<MainView <MainView
v-else v-else
:auth_redirect="auth.redirect"
:preview_mode="is_preview" :preview_mode="is_preview"
:dev_mode="is_dev" :dev_mode="is_dev"
/> />
@ -20,7 +21,11 @@ export default {
"LoginCard": LoginCard, "LoginCard": LoginCard,
"MainView": MainView "MainView": MainView
}, },
data() { return {} }, data() { return {
auth: {
redirect: process.env.NODE_ENV === `production` ? `https://oliver.akins.me/top-lists` : `http://localhost:8080`
}
} },
computed: { computed: {
is_dev() { is_dev() {
let params = new URLSearchParams(window.location.search.slice(1)); let params = new URLSearchParams(window.location.search.slice(1));
@ -53,7 +58,7 @@ export default {
return true return true
} }
} else { } else {
let error = (new URLSearchParams(window.location.search)).get(`error`) let error = (new URLSearchParams(window.location.search.slice(1))).get(`error`)
// Authorization failed, error to the user // Authorization failed, error to the user
if (error !== null) { if (error !== null) {

View file

@ -96,6 +96,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
auth_redirect: {
type: String,
required: true,
}
}, },
components: { components: {
icon: Icon, icon: Icon,
@ -174,7 +178,7 @@ export default {
).then((response) => { ).then((response) => {
if (response.error) { if (response.error) {
window.location.hash = ``; window.location.hash = ``;
window.location.href = `${this.auth.redirect}?error=${encodeURI(response.error)}`; window.location.href = `${this.auth_redirect}?error=${encodeURI(response.error)}`;
return return
} }
let data = response.data; let data = response.data;
@ -184,8 +188,9 @@ export default {
this.user.image = data.images.length > 0 ? data.images[0].url : ``; this.user.image = data.images.length > 0 ? data.images[0].url : ``;
}).catch((err) => { }).catch((err) => {
console/error(err)
window.location.hash = ``; window.location.hash = ``;
window.location.href = `${this.auth.redirect}?error=${encodeURI(err)}`;; window.location.href = `${this.auth_redirect}?error=${encodeURI(err)}`;;
return return
}) })
}); });

View file

@ -12,11 +12,16 @@
<script> <script>
export default { export default {
name: 'LoginView', name: 'LoginView',
props: {
redirect: {
type: String,
required: true,
}
},
data() { return { data() { return {
alert: `We will only be able to access your top tracks and artists, nothing else. This is also only done on your browser. Our servers do not see any of the data from your account.`, alert: `We will only be able to access your top tracks and artists, nothing else. This is also only done on your browser. Our servers do not see any of the data from your account.`,
auth_base: `https://accounts.spotify.com/authorize`, auth_base: `https://accounts.spotify.com/authorize`,
use_state: process.env.NODE_ENV === `production`, use_state: process.env.NODE_ENV === `production`,
redirect: process.env.NODE_ENV === `production` ? `https://oliver.akins.me/top-lists` : `http://localhost:8080`,
client_id: `3a1795e9d55445b0aa0c05dd74c866fb`, client_id: `3a1795e9d55445b0aa0c05dd74c866fb`,
scopes: [ `user-top-read` ], scopes: [ `user-top-read` ],
show_dialog: process.env.NODE_ENV !== `production`, show_dialog: process.env.NODE_ENV !== `production`,

View file

@ -4,6 +4,7 @@
:dev="dev_mode" :dev="dev_mode"
:preview="preview_mode" :preview="preview_mode"
:api_url="api_base" :api_url="api_base"
:auth_redirect="auth_redirect"
:token="get_token()" :token="get_token()"
:data_exists="data.length !== 0" :data_exists="data.length !== 0"
@playlist_export="handle_export" @playlist_export="handle_export"
@ -37,14 +38,15 @@ import UnknownTypeCard from "./cards/UnknownType.vue";
export default { export default {
name: `MainView`, name: `MainView`,
props: { props: {
preview_mode: Boolean, auth_redirect: {
dev_mode: Boolean, type: String,
required: true,
}
}, },
components: { components: {
Control: ControlCard, Control: ControlCard,
Track: TrackCard, Track: TrackCard,
Artist: ArtistCard, Artist: ArtistCard,
Unknown: UnknownTypeCard,
}, },
data() { return { data() { return {
data: [], data: [],