@riligar/auth-elysia 1.4.1 → 1.5.0

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/dist/index.esm.js CHANGED
@@ -139,7 +139,12 @@ class RiLiGarAuthClient {
139
139
  return null
140
140
  }
141
141
 
142
- return payload
142
+ // Map JWT standard claims to user object format
143
+ // JWT uses 'sub' for subject (user ID), but clients expect 'id'
144
+ return {
145
+ id: payload.sub,
146
+ ...payload,
147
+ }
143
148
  } catch (error) {
144
149
  console.warn('JWT local verification failed:', error.message);
145
150
  return null
@@ -276,11 +281,11 @@ function authPlugin(userConfig = {}) {
276
281
  const authClient = new RiLiGarAuthClient(config.apiUrl, config.secretKey);
277
282
 
278
283
  return new Elysia({ name: 'auth-plugin' })
279
- .derive(({ request }) => ({
284
+ .onBeforeHandle(createAuthMiddleware(config, authClient))
285
+ .resolve(({ request }) => ({
280
286
  user: request.user || null,
281
287
  authMeta: request.authMeta || null,
282
288
  }))
283
- .onBeforeHandle(createAuthMiddleware(config, authClient))
284
289
  .group(config.prefix, app =>
285
290
  app
286
291
  // Rota de login
package/dist/index.js CHANGED
@@ -143,7 +143,12 @@ class RiLiGarAuthClient {
143
143
  return null
144
144
  }
145
145
 
146
- return payload
146
+ // Map JWT standard claims to user object format
147
+ // JWT uses 'sub' for subject (user ID), but clients expect 'id'
148
+ return {
149
+ id: payload.sub,
150
+ ...payload,
151
+ }
147
152
  } catch (error) {
148
153
  console.warn('JWT local verification failed:', error.message);
149
154
  return null
@@ -280,11 +285,11 @@ function authPlugin(userConfig = {}) {
280
285
  const authClient = new RiLiGarAuthClient(config.apiUrl, config.secretKey);
281
286
 
282
287
  return new elysia.Elysia({ name: 'auth-plugin' })
283
- .derive(({ request }) => ({
288
+ .onBeforeHandle(createAuthMiddleware(config, authClient))
289
+ .resolve(({ request }) => ({
284
290
  user: request.user || null,
285
291
  authMeta: request.authMeta || null,
286
292
  }))
287
- .onBeforeHandle(createAuthMiddleware(config, authClient))
288
293
  .group(config.prefix, app =>
289
294
  app
290
295
  // Rota de login
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riligar/auth-elysia",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "description": "Auth SDK for ElysiaJS with JWT and JWKS",
6
6
  "main": "dist/index.js",
package/src/index.js CHANGED
@@ -138,7 +138,12 @@ class RiLiGarAuthClient {
138
138
  return null
139
139
  }
140
140
 
141
- return payload
141
+ // Map JWT standard claims to user object format
142
+ // JWT uses 'sub' for subject (user ID), but clients expect 'id'
143
+ return {
144
+ id: payload.sub,
145
+ ...payload,
146
+ }
142
147
  } catch (error) {
143
148
  console.warn('JWT local verification failed:', error.message)
144
149
  return null
@@ -275,11 +280,11 @@ export function authPlugin(userConfig = {}) {
275
280
  const authClient = new RiLiGarAuthClient(config.apiUrl, config.secretKey)
276
281
 
277
282
  return new Elysia({ name: 'auth-plugin' })
278
- .derive(({ request }) => ({
283
+ .onBeforeHandle(createAuthMiddleware(config, authClient))
284
+ .resolve(({ request }) => ({
279
285
  user: request.user || null,
280
286
  authMeta: request.authMeta || null,
281
287
  }))
282
- .onBeforeHandle(createAuthMiddleware(config, authClient))
283
288
  .group(config.prefix, app =>
284
289
  app
285
290
  // Rota de login