Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce user confusion about their authentication status after signin #31

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use libsql::named_params;
use nanoid::nanoid;
use serde::Deserialize;

use self::authenticated_user::AuthenticatedUser;

pub(crate) mod authenticated_user;

//TODO decide how long a session should live
Expand Down Expand Up @@ -231,16 +233,28 @@ struct SignUpTemplate {}
#[derive(Template)]
#[template(path = "sign_in.html")]
struct SignInTemplate {}
async fn sign_up_handler() -> impl IntoResponse {
async fn sign_up_handler(user: Option<AuthenticatedUser>) -> impl IntoResponse {
// Check if is already authenticated and redirect to surveys
// Ideally they should not land on the signup page if they are already authenticated
if user.is_some() {
return Redirect::to("/surveys").into_response();
}

let sign_up_template = SignUpTemplate {};

sign_up_template
sign_up_template.into_response()
}

async fn sign_in_handler() -> impl IntoResponse {
async fn sign_in_handler(user: Option<AuthenticatedUser>) -> impl IntoResponse {
// Check if is already authenticated and redirect to surveys
// Ideally they should not land on the signin page if they are already authenticated
if user.is_some() {
return Redirect::to("/surveys").into_response();
}

let sign_in_template = SignInTemplate {};

sign_in_template
sign_in_template.into_response()
}

#[derive(Template)]
Expand Down