Skip to content

Commit

Permalink
Merge pull request #204 from dfpc-coe/login-redirect
Browse files Browse the repository at this point in the history
Redirect State on Login
  • Loading branch information
ingalls authored Jun 21, 2024
2 parents 5f2bf9c + 34425c9 commit f2eccfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions api/web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ export default {
},
errorCaptured: function(err) {
if (err.message === '401') {
// Popup Modal if reauthenticating vs initial login
this.login = true;
} else if (String(err) === 'Error: Authentication Required') {
this.$router.push('/login');
this.routeLogin();
} else {
this.err = err;
}
Expand All @@ -178,7 +179,7 @@ export default {
await this.getLogin();
await this.getServer();
} else if (this.$route.name !== 'login') {
this.$router.push("/login");
this.routeLogin();
}
this.mounted = true;
Expand All @@ -189,14 +190,19 @@ export default {
delete localStorage.token;
this.$router.push("/login");
},
routeLogin: function() {
this.$router.push(`/login?redirect=${encodeURIComponent(window.location.pathname)}`);
},
getLogin: async function() {
this.loading = true;
try {
this.user = await std('/api/login');
} catch (err) {
this.user = null;
delete localStorage.token;
if (this.$route.name !== 'login') this.$router.push("/login");
if (this.$route.name !== 'login') {
this.routeLogin();
}
this.loading = false;
}
Expand Down
7 changes: 6 additions & 1 deletion api/web/src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ export default {
localStorage.token = login.token;
this.$emit('login');
this.$router.push("/");
if (this.$route.query.redirect) {
this.$router.push(this.$route.query.redirect);
} else {
this.$router.push("/");
}
} catch (err) {
this.loading = false;
throw err;
Expand Down

0 comments on commit f2eccfd

Please sign in to comment.