mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-08 06:59:26 +08:00
fix: test
This commit is contained in:
parent
e2b7c5109e
commit
ddff4e9b7c
@ -187,7 +187,10 @@ export class BaseAuth extends Auth {
|
|||||||
headers: JSON.stringify(this.ctx?.req?.headers),
|
headers: JSON.stringify(this.ctx?.req?.headers),
|
||||||
});
|
});
|
||||||
const expiresIn = Math.floor(tokenPolicy.tokenExpirationTime / 1000);
|
const expiresIn = Math.floor(tokenPolicy.tokenExpirationTime / 1000);
|
||||||
const newToken = this.jwt.sign({ userId, roleName, temp, signInTime }, { jwtid: renewedResult.jti, expiresIn });
|
const newToken = this.jwt.sign(
|
||||||
|
{ userId, roleName, temp, signInTime, iat: Math.floor(renewedResult.issuedTime / 1000) },
|
||||||
|
{ jwtid: renewedResult.jti, expiresIn },
|
||||||
|
);
|
||||||
this.ctx.res.setHeader('x-new-token', newToken);
|
this.ctx.res.setHeader('x-new-token', newToken);
|
||||||
return user;
|
return user;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -57,10 +57,10 @@ export function authCheckMiddleware({ app }: { app: Application }) {
|
|||||||
if (error.status === 401 && !error.config?.skipAuth) {
|
if (error.status === 401 && !error.config?.skipAuth) {
|
||||||
const requestToken = error?.config?.headers?.Authorization?.replace(/^Bearer\s+/gi, '');
|
const requestToken = error?.config?.headers?.Authorization?.replace(/^Bearer\s+/gi, '');
|
||||||
const currentToken = app.apiClient.auth.getToken();
|
const currentToken = app.apiClient.auth.getToken();
|
||||||
if (currentToken && currentToken !== requestToken) {
|
// if (currentToken && currentToken !== requestToken) {
|
||||||
error.config.skipNotify = true;
|
// error.config.skipNotify = true;
|
||||||
return app.apiClient.request(error.config);
|
// return app.apiClient.request(error.config);
|
||||||
}
|
// }
|
||||||
app.apiClient.auth.setToken('');
|
app.apiClient.auth.setToken('');
|
||||||
const errors = error?.response?.data?.errors;
|
const errors = error?.response?.data?.errors;
|
||||||
const firstError = Array.isArray(errors) ? errors[0] : null;
|
const firstError = Array.isArray(errors) ? errors[0] : null;
|
||||||
|
@ -108,20 +108,7 @@ export class TokenController implements TokenControlService {
|
|||||||
renew: TokenControlService['renew'] = async (jti) => {
|
renew: TokenControlService['renew'] = async (jti) => {
|
||||||
const repo = this.app.db.getRepository(issuedTokensCollectionName);
|
const repo = this.app.db.getRepository(issuedTokensCollectionName);
|
||||||
const model = this.app.db.getModel(issuedTokensCollectionName);
|
const model = this.app.db.getModel(issuedTokensCollectionName);
|
||||||
const exists = await repo.findOne({ filter: { jti } });
|
|
||||||
if (!exists) {
|
|
||||||
this.logger.error('jti not found', {
|
|
||||||
module: 'auth',
|
|
||||||
submodule: 'token-controller',
|
|
||||||
method: 'renew',
|
|
||||||
jti,
|
|
||||||
code: AuthErrorCode.TOKEN_RENEW_FAILED,
|
|
||||||
});
|
|
||||||
throw new AuthError({
|
|
||||||
message: 'Your session has expired. Please sign in again.',
|
|
||||||
code: AuthErrorCode.TOKEN_RENEW_FAILED,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const newId = randomUUID();
|
const newId = randomUUID();
|
||||||
const issuedTime = Date.now();
|
const issuedTime = Date.now();
|
||||||
|
|
||||||
@ -132,8 +119,15 @@ export class TokenController implements TokenControlService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (count === 1) {
|
if (count === 1) {
|
||||||
|
await this.cache.set(`jti-renewed-cahce:${jti}`, { jti: newId, issuedTime }, 20000);
|
||||||
|
this.logger.info('jti renewed', { oldJti: jti, newJti: newId, issuedTime });
|
||||||
return { jti: newId, issuedTime };
|
return { jti: newId, issuedTime };
|
||||||
} else {
|
} else {
|
||||||
|
const cachedJtiData = await this.cache.get(`jti-renewed-cahce:${jti}`);
|
||||||
|
if (cachedJtiData) {
|
||||||
|
return cachedJtiData as { jti: string; issuedTime: EpochTimeStamp };
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.error('jti renew failed', {
|
this.logger.error('jti renew failed', {
|
||||||
module: 'auth',
|
module: 'auth',
|
||||||
submodule: 'token-controller',
|
submodule: 'token-controller',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user