Finished inaugural login and signup pages

modified:   src/pages/login.rs
	modified:   src/pages/signup.rs
This commit is contained in:
Danny Zou 2024-02-23 16:24:05 -05:00
parent 2ab1f44317
commit 5650882ba8
2 changed files with 10 additions and 4 deletions

View File

@ -1,8 +1,8 @@
use crate::auth::login;
use leptos::leptos_dom::*; use leptos::leptos_dom::*;
use leptos::*; use leptos::*;
use leptos_icons::IoIcon::*; use leptos_icons::IoIcon::*;
use leptos_icons::*; use leptos_icons::*;
use crate::auth::login;
#[component] #[component]
pub fn Login() -> impl IntoView { pub fn Login() -> impl IntoView {
@ -12,13 +12,19 @@ pub fn Login() -> impl IntoView {
let on_submit = move |ev: leptos::ev::SubmitEvent| { let on_submit = move |ev: leptos::ev::SubmitEvent| {
ev.prevent_default(); ev.prevent_default();
let username_or_email1 = username_or_email.get();
let password1 = password.get();
spawn_local(async move { spawn_local(async move {
if let Err(err) = login(username_or_email.get(), password.get()).await { let login_result = login(username_or_email1, password1).await;
if let Err(err) = login_result {
// Handle the error here, e.g., log it or display to the user // Handle the error here, e.g., log it or display to the user
log!("Error logging in: {:?}", err); log!("Error logging in: {:?}", err);
} else { } else if let Ok(true) = login_result {
// Redirect to the login page // Redirect to the login page
log!("Logged in Successfully!"); log!("Logged in Successfully!");
} else if let Ok(false) = login_result {
log!("Invalid username or password");
} }
}); });
}; };

View File

@ -21,7 +21,7 @@ pub fn Signup() -> impl IntoView {
password: Some(password.get()), password: Some(password.get()),
created_at: None, created_at: None,
}; };
log!("new user: {:?}", new_user);
spawn_local(async move { spawn_local(async move {
if let Err(err) = signup(new_user).await { if let Err(err) = signup(new_user).await {
// Handle the error here, e.g., log it or display to the user // Handle the error here, e.g., log it or display to the user