1
This commit is contained in:
@@ -15,6 +15,12 @@ export interface User {
|
|||||||
is_superuser: boolean;
|
is_superuser: boolean;
|
||||||
last_login: string | null;
|
last_login: string | null;
|
||||||
date_joined: string;
|
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;
|
isLogin: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
expiresAtTimestamp: number | null;
|
expires_at_timestamp: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ErrorResponse {
|
export interface ErrorResponse {
|
||||||
@@ -71,7 +77,7 @@ const initialState: AuthState = {
|
|||||||
isLogin: !!localStorage.getItem("access_token"),
|
isLogin: !!localStorage.getItem("access_token"),
|
||||||
error: null,
|
error: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
expiresIn: localStorage.getItem("expires_at_timestamp")
|
expires_at_timestamp: localStorage.getItem("expires_at_timestamp")
|
||||||
? parseInt(localStorage.getItem("expires_at_timestamp")!, 10)
|
? parseInt(localStorage.getItem("expires_at_timestamp")!, 10)
|
||||||
: null,
|
: null,
|
||||||
};
|
};
|
||||||
@@ -195,7 +201,7 @@ const authSlice = createSlice({
|
|||||||
state.tokenType = null;
|
state.tokenType = null;
|
||||||
state.isLogin = false;
|
state.isLogin = false;
|
||||||
state.error = null;
|
state.error = null;
|
||||||
state.expiresAtTimestamp = null;
|
state.expires_at_timestamp = null;
|
||||||
|
|
||||||
// 删除 localStorage 中的 token
|
// 删除 localStorage 中的 token
|
||||||
localStorage.removeItem("access_token");
|
localStorage.removeItem("access_token");
|
||||||
@@ -219,7 +225,7 @@ const authSlice = createSlice({
|
|||||||
state.accessToken = action.payload.access;
|
state.accessToken = action.payload.access;
|
||||||
state.refreshToken = action.payload.refresh;
|
state.refreshToken = action.payload.refresh;
|
||||||
state.tokenType = action.payload.token_type;
|
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;
|
state.isLogin = true;
|
||||||
})
|
})
|
||||||
.addCase(emailCodeLogin.rejected, (state, action) => {
|
.addCase(emailCodeLogin.rejected, (state, action) => {
|
||||||
@@ -275,5 +281,5 @@ export const selectTokenType = (state: { auth: AuthState }) =>
|
|||||||
state.auth.tokenType;
|
state.auth.tokenType;
|
||||||
export const selectIsLogin = (state: { auth: AuthState }) => state.auth.isLogin;
|
export const selectIsLogin = (state: { auth: AuthState }) => state.auth.isLogin;
|
||||||
export const selectExpiresAtTimestamp = (state: { auth: AuthState }) =>
|
export const selectExpiresAtTimestamp = (state: { auth: AuthState }) =>
|
||||||
state.auth.expiresAtTimestamp;
|
state.auth.expires_at_timestamp;
|
||||||
export const selectLoading = (state: { auth: AuthState }) => state.auth.loading;
|
export const selectLoading = (state: { auth: AuthState }) => state.auth.loading;
|
||||||
|
|||||||
+977
-54
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user