@maximemrf/adonisjs-jwt 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -204,8 +204,9 @@ const refreshToken = await User.refreshTokens.create(user)
204
204
  // if you use the refresh token
205
205
  router.post('jwt/refresh', async ({ auth }) => {
206
206
  // this will authenticate the user using the refresh token
207
- // it will delete the old refresh token and generate a new one
208
- const user = await auth.use('jwt').authenticateWithRefreshToken()
207
+ // it will delete the old refresh token and generate a new one with the same abilities
208
+ // You could pass a name for the new token as well
209
+ const user = await auth.use('jwt').authenticateWithRefreshToken('optional_name')
209
210
  const newRefreshToken = user.currentToken
210
211
  const newToken = await auth.use('jwt').generate(user)
211
212
 
@@ -46,7 +46,7 @@ export declare class JwtGuard<UserProvider extends JwtUserProviderContract<unkno
46
46
  authenticate(): Promise<UserProvider[typeof symbols.PROVIDER_REAL_USER] & {
47
47
  currentToken: string;
48
48
  }>;
49
- authenticateWithRefreshToken(): Promise<UserProvider[typeof symbols.PROVIDER_REAL_USER] & {
49
+ authenticateWithRefreshToken(name?: string): Promise<UserProvider[typeof symbols.PROVIDER_REAL_USER] & {
50
50
  currentToken: string;
51
51
  }>;
52
52
  /**
package/build/src/jwt.js CHANGED
@@ -135,7 +135,7 @@ export class JwtGuard {
135
135
  this.user.currentToken = token;
136
136
  return this.getUserOrFail();
137
137
  }
138
- async authenticateWithRefreshToken() {
138
+ async authenticateWithRefreshToken(name) {
139
139
  /**
140
140
  * Avoid re-authentication when it has been done already
141
141
  * for the given request
@@ -187,6 +187,10 @@ export class JwtGuard {
187
187
  }
188
188
  this.isAuthenticated = true;
189
189
  this.user = providerUser.getOriginal();
190
+ /**
191
+ * Get the same abilities for the new refresh token
192
+ */
193
+ const abilities = accessToken.abilities;
190
194
  /**
191
195
  * Delete the refresh token from the database
192
196
  */
@@ -196,7 +200,9 @@ export class JwtGuard {
196
200
  guardDriverName: this.driverName,
197
201
  });
198
202
  }
199
- const newRefreshToken = await this.#refreshTokenUserProvider.createToken(this.user);
203
+ const newRefreshToken = await this.#refreshTokenUserProvider.createToken(this.user, abilities, {
204
+ name,
205
+ });
200
206
  if (!newRefreshToken.value) {
201
207
  throw new errors.E_UNAUTHORIZED_ACCESS('Unauthorized access', {
202
208
  guardDriverName: this.driverName,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maximemrf/adonisjs-jwt",
3
3
  "description": "Adonisjs v6 package for authentication with jwt token",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "engines": {
6
6
  "node": ">=20.6.0"
7
7
  },
@@ -44,7 +44,7 @@
44
44
  "@japa/assert": "^4.0.1",
45
45
  "@japa/file-system": "^2.3.2",
46
46
  "@japa/runner": "^4.2.0",
47
- "@swc/core": "1.11.24",
47
+ "@swc/core": "^1.12.5",
48
48
  "@types/node": "^22.15.18",
49
49
  "c8": "^9.1.0",
50
50
  "copyfiles": "^2.4.1",