mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-07 07:23:22 +00:00
fix: login after signup
Also resolves entire user object being return to client, including password_hash... ⚠️
This commit is contained in:
@@ -118,9 +118,21 @@ router.post(
|
||||
// Create default dashboard preferences for the new admin user
|
||||
await createDefaultDashboardPreferences(user.id, "admin");
|
||||
|
||||
// Generate token for immediate login
|
||||
const token = generateToken(user.id);
|
||||
|
||||
res.status(201).json({
|
||||
message: "Admin user created successfully",
|
||||
user: user,
|
||||
token,
|
||||
user: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
is_active: user.is_active,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error creating admin user:", error);
|
||||
|
||||
@@ -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