mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-05 22:43:23 +00:00
fix: login after signup
Also resolves entire user object being return to client, including password_hash... ⚠️
This commit is contained in:
@@ -3,7 +3,7 @@ import { useId, useState } from "react";
|
||||
import { useAuth } from "../contexts/AuthContext";
|
||||
|
||||
const FirstTimeAdminSetup = () => {
|
||||
const { login } = useAuth();
|
||||
const { login, setAuthState } = useAuth();
|
||||
const firstNameId = useId();
|
||||
const lastNameId = useId();
|
||||
const usernameId = useId();
|
||||
@@ -95,10 +95,18 @@ const FirstTimeAdminSetup = () => {
|
||||
|
||||
if (response.ok) {
|
||||
setSuccess(true);
|
||||
// Auto-login the user after successful setup
|
||||
setTimeout(() => {
|
||||
login(formData.username.trim(), formData.password);
|
||||
}, 2000);
|
||||
|
||||
// If the response includes a token, use it to automatically log in
|
||||
if (data.token && data.user) {
|
||||
// Auto-login using the token from the setup response
|
||||
setAuthState(data.token, data.user);
|
||||
setTimeout(() => {}, 2000);
|
||||
} else {
|
||||
// Fallback to manual login if no token provided
|
||||
setTimeout(() => {
|
||||
login(formData.username.trim(), formData.password);
|
||||
}, 2000);
|
||||
}
|
||||
} else {
|
||||
setError(data.error || "Failed to create admin user");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user