ac76150915
- Add auth-api for handling login requests. - Update index.ts to export AuthApi. - Modify HeroLayout to display username or login link based on authentication state. - Create LoginPage component for user login. - Update router to include login route with EmptyLayout. - Configure WebClient to include credentials in requests. - Add auth-slice for managing authentication state in Redux. - Update Redux store to include auth reducer. - Define LoginRequest and User types in types/index.ts. - Configure Vite to proxy API requests to the backend server.
27 lines
551 B
TypeScript
27 lines
551 B
TypeScript
import { createSlice, PayloadAction } from "@reduxjs/toolkit"
|
|
import { User } from "@/types"
|
|
|
|
interface AuthState {
|
|
user: User | null
|
|
}
|
|
|
|
const initialState: AuthState = {
|
|
user: null,
|
|
}
|
|
|
|
const authSlice = createSlice({
|
|
name: "auth",
|
|
initialState,
|
|
reducers: {
|
|
setCurrentUser(state, action: PayloadAction<User>) {
|
|
state.user = action.payload
|
|
},
|
|
clearCurrentUser(state) {
|
|
state.user = null
|
|
},
|
|
},
|
|
})
|
|
|
|
export const { setCurrentUser, clearCurrentUser } = authSlice.actions
|
|
export const authReducer = authSlice.reducer
|