Skip to content

Commit

Permalink
Merge pull request #1788 from OpenC3/login-redirect
Browse files Browse the repository at this point in the history
Small login bugs
  • Loading branch information
ryan-pratt authored Dec 20, 2024
2 parents b25adc7 + 2b9b289 commit 6e9db63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ export default {
window.location.pathname == '/tools' ||
window.location.pathname == '/tools/'
) {
// TODO: There's some sort of race condition here which makes this flaky if the user went to '/login' with
// no `?redirect=` query param while they were already authenticated. That sends them to '/', causing
// another redirect here that gets stepped on, so they're left at '/'. The nav bar shows, so they can click
// on a tool, or refresh the page to make this redirect actually happen.
for (let key of Object.keys(this.shownTools)) {
if (this.appNav[key].shown) {
history.replaceState(null, '', this.appNav[key].url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<v-row>
<v-btn
type="submit"
@click.prevent="verifyPassword"
@click.prevent="() => verifyPassword()"
size="large"
color="success"
:disabled="!formValid"
Expand Down Expand Up @@ -138,6 +138,11 @@ export default {
}
})
},
mounted: function () {
if (localStorage.openc3Token) {
this.verifyPassword(localStorage.openc3Token, true)
}
},
methods: {
showReset: function () {
this.reset = true
Expand All @@ -147,28 +152,33 @@ export default {
const redirect = new URLSearchParams(window.location.search).get(
'redirect',
)
if (redirect.startsWith('/tools/')) {
if (redirect?.startsWith('/tools/')) {
// Valid relative redirect URL
window.location = decodeURI(redirect)
} else {
window.location = '/'
}
},
verifyPassword: function () {
verifyPassword: function (token, noAlert) {
token ||= this.password
this.showAlert = false
Api.post('/openc3-api/auth/verify', {
data: {
token: this.password,
token,
},
...this.options,
})
.then((response) => {
this.login(response)
})
.catch((error) => {
this.alert = 'Incorrect password'
if (error?.status === 401) {
this.alert = 'Incorrect password'
} else {
this.alert = error.message || 'Something went wrong...'
}
this.alertType = 'warning'
this.showAlert = true
this.showAlert = !noAlert
})
},
setPassword: function () {
Expand Down

0 comments on commit 6e9db63

Please sign in to comment.