This commit is contained in:
2026-04-12 18:27:58 +08:00
parent 32fd3c30f8
commit 8970093e25
2 changed files with 988 additions and 59 deletions
+11 -5
View File
@@ -15,6 +15,12 @@ export interface User {
is_superuser: boolean;
last_login: string | null;
date_joined: string;
gender: number;
avatar: string;
bio: string;
location: string;
phone: string;
is_set_password: boolean;
}
// 登录响应类型
@@ -45,7 +51,7 @@ export interface AuthState {
isLogin: boolean;
error: string | null;
loading: boolean;
expiresAtTimestamp: number | null;
expires_at_timestamp: number | null;
}
export interface ErrorResponse {
@@ -71,7 +77,7 @@ const initialState: AuthState = {
isLogin: !!localStorage.getItem("access_token"),
error: null,
loading: false,
expiresIn: localStorage.getItem("expires_at_timestamp")
expires_at_timestamp: localStorage.getItem("expires_at_timestamp")
? parseInt(localStorage.getItem("expires_at_timestamp")!, 10)
: null,
};
@@ -195,7 +201,7 @@ const authSlice = createSlice({
state.tokenType = null;
state.isLogin = false;
state.error = null;
state.expiresAtTimestamp = null;
state.expires_at_timestamp = null;
// 删除 localStorage 中的 token
localStorage.removeItem("access_token");
@@ -219,7 +225,7 @@ const authSlice = createSlice({
state.accessToken = action.payload.access;
state.refreshToken = action.payload.refresh;
state.tokenType = action.payload.token_type;
state.expiresAtTimestamp = action.payload.expires_at_timestamp;
state.expires_at_timestamp = action.payload.expires_at_timestamp;
state.isLogin = true;
})
.addCase(emailCodeLogin.rejected, (state, action) => {
@@ -275,5 +281,5 @@ export const selectTokenType = (state: { auth: AuthState }) =>
state.auth.tokenType;
export const selectIsLogin = (state: { auth: AuthState }) => state.auth.isLogin;
export const selectExpiresAtTimestamp = (state: { auth: AuthState }) =>
state.auth.expiresAtTimestamp;
state.auth.expires_at_timestamp;
export const selectLoading = (state: { auth: AuthState }) => state.auth.loading;
File diff suppressed because it is too large Load Diff