Selaa lähdekoodia

CADD 2026 #12 fix refresh token are not revocable

CR023
Jason Chuang 1 viikko sitten
vanhempi
commit
bd74b6b36b
2 muutettua tiedostoa jossa 8 lisäystä ja 2 poistoa
  1. +7
    -2
      src/auth/index.js
  2. +1
    -0
      src/utils/ApiPathConst.js

+ 7
- 2
src/auth/index.js Näytä tiedosto

@@ -12,7 +12,7 @@ export const predictUsageCount = 'predictUsageCount'
export const windowCount = 'windowCount' export const windowCount = 'windowCount'
import {useNavigate} from "react-router-dom"; import {useNavigate} from "react-router-dom";
import {useDispatch} from "react-redux"; import {useDispatch} from "react-redux";
import { REFRESH_TOKEN } from 'utils/ApiPathConst';
import { LOGOUT, REFRESH_TOKEN } from 'utils/ApiPathConst';
import { getMessage } from 'utils/getI18nMessage'; import { getMessage } from 'utils/getI18nMessage';


// Guard so we only register interceptors once (ThemeRoutes re-renders add duplicate handlers otherwise) // Guard so we only register interceptors once (ThemeRoutes re-renders add duplicate handlers otherwise)
@@ -22,7 +22,7 @@ let expiredAlertShownInMemory = false;


/** Login / public auth endpoints must not trigger token refresh or session-expiry reload. */ /** Login / public auth endpoints must not trigger token refresh or session-expiry reload. */
const isPublicAuthRequest = (reqUrl) => const isPublicAuthRequest = (reqUrl) =>
reqUrl.includes('/login');
reqUrl.includes('/login') || reqUrl.includes('/refresh-token') || reqUrl.includes('/logout');


/** Clear stale session-expiry flag so a new login attempt can show its own error dialog. */ /** Clear stale session-expiry flag so a new login attempt can show its own error dialog. */
export const clearExpiredSessionAlert = () => { export const clearExpiredSessionAlert = () => {
@@ -96,6 +96,11 @@ export const isTokenValid = () =>{
// ** Handle User Logout // ** Handle User Logout
export const handleLogoutFunction = () => { export const handleLogoutFunction = () => {
return dispatch => { return dispatch => {
const refreshToken = localStorage.getItem('refreshToken')
if (refreshToken) {
axios.post(`${apiPath}${LOGOUT}`, { refreshToken }).catch(() => {})
}

dispatch({ dispatch({
type: 'LOGOUT', type: 'LOGOUT',
accessToken: null, accessToken: null,


+ 1
- 0
src/utils/ApiPathConst.js Näytä tiedosto

@@ -5,6 +5,7 @@ import {


// GET request // GET request
export const REFRESH_TOKEN = "/refresh-token" export const REFRESH_TOKEN = "/refresh-token"
export const LOGOUT = "/logout"
export const CHANGE_PASSWORD_PATH = "/user/change-password" export const CHANGE_PASSWORD_PATH = "/user/change-password"


export const GET_SYS_PARAMS = apiPath+'/settings'; export const GET_SYS_PARAMS = apiPath+'/settings';


Ladataan…
Peruuta
Tallenna