Files
react-template/src/store/auth-slice.ts
T

63 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-03-26 19:06:46 +08:00
import { createSlice } from "@reduxjs/toolkit"
2025-08-03 11:42:24 +08:00
/**
* Defines the structure of the authentication state within the Redux store.
*/
2025-03-26 19:06:46 +08:00
interface AuthState {
2025-08-03 11:42:24 +08:00
/**
* Indicates whether a user is currently authenticated.
* @type {boolean}
*/
2025-03-26 19:06:46 +08:00
isAuthenticated: boolean
}
2025-08-03 11:42:24 +08:00
/**
* The initial state for the authentication slice.
*
* By default, the user is considered unauthenticated.
*
* @constant
* @type {AuthState}
*/
2025-03-26 19:06:46 +08:00
const initialState: AuthState = {
isAuthenticated: false
}
2025-08-03 11:42:24 +08:00
/**
* A Redux Toolkit slice for managing authentication-related state.
*
* This slice includes the reducer, actions, and initial state for the authentication feature.
* Currently, it only defines the initial state and no specific reducers, meaning it only
* holds the `isAuthenticated` flag.
*/
2025-03-26 19:06:46 +08:00
const authSlice = createSlice({
2025-08-03 11:42:24 +08:00
/**
* The name of the slice, used to generate action types.
* @type {string}
*/
2025-03-26 19:06:46 +08:00
name: "auth",
2025-08-03 11:42:24 +08:00
/**
* The initial state for this slice.
* @type {AuthState}
*/
2025-03-26 19:06:46 +08:00
initialState,
2025-08-03 11:42:24 +08:00
/**
* An object of reducer functions. Currently empty, meaning no actions are explicitly defined for
* state modification within this slice.
* @type {object}
*/
2025-03-26 19:06:46 +08:00
reducers: {
}
})
// export const { } = authSlice.actions
2025-08-03 11:42:24 +08:00
/**
* The reducer function for the authentication slice.
*
* This is the default export and should be combined with other reducers in the Redux store.
*
* @default
*/
2025-03-26 19:06:46 +08:00
export default authSlice.reducer