Skip to content

Commit

Permalink
fix: more robust login functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
zleyyij committed Jul 16, 2024
1 parent ecc1cb9 commit ee8be35
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 1 addition & 2 deletions backend/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Interface {

/// Create or overwrite the document at the provided `path` and populate it with the value of `new_doc`.
/// `message` will be included in the commit message, and `token` is a valid github auth token.
///
///
/// # Panics
/// This function will panic if it's called when the repo mutex is already held by the current thread
///
Expand Down Expand Up @@ -184,7 +184,6 @@ impl Interface {
debug!("Commit cleanup completed");
Ok(())
}

}

/// If the repository at the provided path exists, open it and fetch the latest changes from the `master` branch.
Expand Down
5 changes: 1 addition & 4 deletions backend/src/handlers_prelude/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ async fn get_oath_processor(
.expires_in()
.wrap_err("Discord OAuth2 response didn't include an expiration date")?;
// Update the user entry if one is already there, otherwise create a user
if let Some(existing_user) = all_users
.iter()
.find(|u| u.username == discord_user_info.username)
{
if let Some(existing_user) = all_users.iter().find(|u| u.token == *token) {
state
.db
.update_user(&User {
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@
}, 800);
return;
}
const loginResponse = await fetch(`${apiAddress}/api/users/me`, { credentials: 'include' });
// Unauthorized, need to login
if (loginResponse.status === 401) {
addToast({
message: 'Your login has expired, redirecting...',
type: ToastType.Error,
dismissible: false
});
setTimeout(() => {
// TODO: When .html stripping middleware is complete, change this to always redirect to /login`
if (dev) {
window.location.href = '/login';
} else {
window.location.href = '/login.html';
}
}, 800);
return;
}
me.set(await (await fetch(`${apiAddress}/api/users/me`, { credentials: 'include' })).json());
me.subscribe((me) => {
if (me.id === -1) {
Expand Down

0 comments on commit ee8be35

Please sign in to comment.