navigation to home page after login and signup

This commit is contained in:
2024-02-27 16:23:53 -05:00
parent 7236e09b4b
commit 1c4ce06064
5 changed files with 14 additions and 25 deletions

View File

@ -4,7 +4,6 @@ use leptos::*;
use leptos_icons::AiIcon::*;
use leptos_icons::IoIcon::*;
use leptos_icons::*;
use leptos_router::*;
#[component]
pub fn Login() -> impl IntoView {
@ -18,16 +17,12 @@ pub fn Login() -> impl IntoView {
log!("showing password");
};
let navigate = leptos_router::use_navigate();
let on_submit = move |ev: leptos::ev::SubmitEvent| {
ev.prevent_default();
let username_or_email1 = username_or_email.get();
let password1 = password.get();
let mut success: bool = false;
spawn_local(async move {
let login_result = login(username_or_email1, password1).await;
if let Err(err) = login_result {
@ -36,15 +31,12 @@ pub fn Login() -> impl IntoView {
} else if let Ok(true) = login_result {
// Redirect to the login page
log!("Logged in Successfully!");
success = true;
leptos_router::use_navigate()("/", Default::default());
log!("Navigated to home page after login");
} else if let Ok(false) = login_result {
log!("Invalid username or password");
}
});
if success {
navigate("/", Default::default());
log!("navigated to home after login");
}
};
view! {

View File

@ -31,10 +31,8 @@ pub fn Signup() -> impl IntoView {
password: Some(password.get()),
created_at: None,
};
let mut success: bool = false;
log!("new user: {:?}", new_user);
spawn_local(async move {
if let Err(err) = signup(new_user).await {
// Handle the error here, e.g., log it or display to the user
@ -42,13 +40,10 @@ pub fn Signup() -> impl IntoView {
} else {
// Redirect to the login page
log!("Signed up successfully!");
success = true;
leptos_router::use_navigate()("/", Default::default());
log!("Navigated to home page after signup")
}
});
if success {
navigate("/", Default::default());
log!("navigated to home after signup");
}
};
view! {
@ -100,7 +95,7 @@ pub fn Signup() -> impl IntoView {
</div>
<input type="submit" value="Sign Up" />
<span class="go-to-login">
Already Have an Account? <a href="/login">Go to Login</a>
Already Have an Account? <a href="/login" class="link" >Go to Login</a>
</span>
</form>
</div>