mirror of
https://github.com/freedbygrace/ActiveDirectoryManager.git
synced 2026-07-26 11:59:14 +00:00
Fix: Redirect users to the dashboard after successful login
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/a1462f8b-9e4f-4acf-a0a4-a2ee5c1f4036.jpg
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import * as React from "react";
|
||||
import { useLocation } from "wouter";
|
||||
import { z } from "zod";
|
||||
import { useForm } from "react-hook-form";
|
||||
@@ -54,6 +55,13 @@ export default function AuthPage() {
|
||||
const { toast } = useToast();
|
||||
const auth = useAuth();
|
||||
|
||||
// Redirect if already logged in
|
||||
React.useEffect(() => {
|
||||
if (auth.user) {
|
||||
navigate("/");
|
||||
}
|
||||
}, [auth.user, navigate]);
|
||||
|
||||
// Login form
|
||||
const loginForm = useForm<LoginFormValues>({
|
||||
resolver: zodResolver(loginSchema),
|
||||
@@ -81,14 +89,28 @@ export default function AuthPage() {
|
||||
// Handle login form submission
|
||||
const onLoginSubmit = (data: LoginFormValues) => {
|
||||
const { username, password } = data;
|
||||
auth.loginMutation.mutate({ username, password });
|
||||
auth.loginMutation.mutate(
|
||||
{ username, password },
|
||||
{
|
||||
onSuccess: () => {
|
||||
navigate("/");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// Handle register form submission
|
||||
const onRegisterSubmit = (data: RegisterFormValues) => {
|
||||
// Remove confirmPassword and acceptTerms which aren't part of the API request
|
||||
const { confirmPassword, acceptTerms, ...registerData } = data;
|
||||
auth.registerMutation.mutate(registerData);
|
||||
auth.registerMutation.mutate(
|
||||
registerData,
|
||||
{
|
||||
onSuccess: () => {
|
||||
navigate("/");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user