mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-10 00:45:39 +00:00
Fixed authentication redirect upon signin using states
Finally fixed dashboard defaults for new user signups
This commit is contained in:
@@ -255,6 +255,13 @@ export const AuthProvider = ({ children }) => {
|
||||
}
|
||||
}, [token, user, checkAdminUsersExist])
|
||||
|
||||
const setAuthState = (authToken, authUser) => {
|
||||
setToken(authToken)
|
||||
setUser(authUser)
|
||||
localStorage.setItem('token', authToken)
|
||||
localStorage.setItem('user', JSON.stringify(authUser))
|
||||
}
|
||||
|
||||
const value = {
|
||||
user,
|
||||
token,
|
||||
@@ -267,6 +274,7 @@ export const AuthProvider = ({ children }) => {
|
||||
updateProfile,
|
||||
changePassword,
|
||||
refreshPermissions,
|
||||
setAuthState,
|
||||
isAuthenticated,
|
||||
isAdmin,
|
||||
hasPermission,
|
||||
|
||||
@@ -24,7 +24,7 @@ const Login = () => {
|
||||
const [signupEnabled, setSignupEnabled] = useState(false)
|
||||
|
||||
const navigate = useNavigate()
|
||||
const { login } = useAuth()
|
||||
const { login, setAuthState } = useAuth()
|
||||
|
||||
// Check if signup is enabled
|
||||
useEffect(() => {
|
||||
@@ -80,9 +80,8 @@ const Login = () => {
|
||||
try {
|
||||
const response = await authAPI.signup(formData.username, formData.email, formData.password, formData.firstName, formData.lastName)
|
||||
if (response.data && response.data.token) {
|
||||
// Store token and user data
|
||||
localStorage.setItem('token', response.data.token)
|
||||
localStorage.setItem('user', JSON.stringify(response.data.user))
|
||||
// Update AuthContext state and localStorage
|
||||
setAuthState(response.data.token, response.data.user)
|
||||
|
||||
// Redirect to dashboard
|
||||
navigate('/')
|
||||
|
||||
Reference in New Issue
Block a user