mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +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),
|
||||
});
|
||||
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);
|
||||
return user;
|
||||
} catch (err) {
|
||||
|
@ -57,10 +57,10 @@ export function authCheckMiddleware({ app }: { app: Application }) {
|
||||
if (error.status === 401 && !error.config?.skipAuth) {
|
||||
const requestToken = error?.config?.headers?.Authorization?.replace(/^Bearer\s+/gi, '');
|
||||
const currentToken = app.apiClient.auth.getToken();
|
||||
if (currentToken && currentToken !== requestToken) {
|
||||
error.config.skipNotify = true;
|
||||
return app.apiClient.request(error.config);
|
||||
}
|
||||
// if (currentToken && currentToken !== requestToken) {
|
||||
// error.config.skipNotify = true;
|
||||
// return app.apiClient.request(error.config);
|
||||
// }
|
||||
app.apiClient.auth.setToken('');
|
||||
const errors = error?.response?.data?.errors;
|
||||
const firstError = Array.isArray(errors) ? errors[0] : null;
|
||||
|
@ -108,20 +108,7 @@ export class TokenController implements TokenControlService {
|
||||
renew: TokenControlService['renew'] = async (jti) => {
|
||||
const repo = this.app.db.getRepository(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 issuedTime = Date.now();
|
||||
|
||||
@ -132,8 +119,15 @@ export class TokenController implements TokenControlService {
|
||||
);
|
||||
|
||||
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 };
|
||||
} 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', {
|
||||
module: 'auth',
|
||||
submodule: 'token-controller',
|
||||
|
Loading…
x
Reference in New Issue
Block a user