@riligar/auth-elysia 1.6.3 → 1.6.4

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
@@ -20,7 +20,14 @@ const DEFAULT_CONFIG = {
20
20
  excludePaths: ['/auth/login', '/auth/register', '/auth/session'],
21
21
  onUnauthorized: set => {
22
22
  set.status = 401;
23
- return 'Sessão inválida ou expirada.'
23
+ set.headers = { ...set.headers, 'Content-Type': 'application/json' };
24
+ return {
25
+ success: false,
26
+ error: {
27
+ code: 'UNAUTHORIZED',
28
+ message: 'Sessão inválida ou expirada. Por favor, faça login novamente.',
29
+ },
30
+ }
24
31
  },
25
32
  };
26
33
 
@@ -113,9 +120,17 @@ function authPlugin(userConfig = {}) {
113
120
  if (!user) return config.onUnauthorized(set)
114
121
  })
115
122
  .error(({ error, set }) => {
116
- if (String(error).includes('user.id') || String(error).includes('of null')) {
123
+ const errorStr = String(error);
124
+ if (errorStr.includes('user.id') || errorStr.includes('of null') || errorStr.includes('of undefined')) {
117
125
  set.status = 401;
118
- return 'Sessão inválida ou expirada.'
126
+ set.headers['Content-Type'] = 'application/json';
127
+ return {
128
+ success: false,
129
+ error: {
130
+ code: 'UNAUTHORIZED',
131
+ message: 'Sessão inválida ou expirada. Por favor, faça login novamente.',
132
+ },
133
+ }
119
134
  }
120
135
  })
121
136
  .group(config.prefix, app =>
package/dist/index.js CHANGED
@@ -24,7 +24,14 @@ const DEFAULT_CONFIG = {
24
24
  excludePaths: ['/auth/login', '/auth/register', '/auth/session'],
25
25
  onUnauthorized: set => {
26
26
  set.status = 401;
27
- return 'Sessão inválida ou expirada.'
27
+ set.headers = { ...set.headers, 'Content-Type': 'application/json' };
28
+ return {
29
+ success: false,
30
+ error: {
31
+ code: 'UNAUTHORIZED',
32
+ message: 'Sessão inválida ou expirada. Por favor, faça login novamente.',
33
+ },
34
+ }
28
35
  },
29
36
  };
30
37
 
@@ -117,9 +124,17 @@ function authPlugin(userConfig = {}) {
117
124
  if (!user) return config.onUnauthorized(set)
118
125
  })
119
126
  .error(({ error, set }) => {
120
- if (String(error).includes('user.id') || String(error).includes('of null')) {
127
+ const errorStr = String(error);
128
+ if (errorStr.includes('user.id') || errorStr.includes('of null') || errorStr.includes('of undefined')) {
121
129
  set.status = 401;
122
- return 'Sessão inválida ou expirada.'
130
+ set.headers['Content-Type'] = 'application/json';
131
+ return {
132
+ success: false,
133
+ error: {
134
+ code: 'UNAUTHORIZED',
135
+ message: 'Sessão inválida ou expirada. Por favor, faça login novamente.',
136
+ },
137
+ }
123
138
  }
124
139
  })
125
140
  .group(config.prefix, app =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riligar/auth-elysia",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
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
@@ -19,7 +19,14 @@ const DEFAULT_CONFIG = {
19
19
  excludePaths: ['/auth/login', '/auth/register', '/auth/session'],
20
20
  onUnauthorized: set => {
21
21
  set.status = 401
22
- return 'Sessão inválida ou expirada.'
22
+ set.headers = { ...set.headers, 'Content-Type': 'application/json' }
23
+ return {
24
+ success: false,
25
+ error: {
26
+ code: 'UNAUTHORIZED',
27
+ message: 'Sessão inválida ou expirada. Por favor, faça login novamente.',
28
+ },
29
+ }
23
30
  },
24
31
  }
25
32
 
@@ -112,9 +119,17 @@ export function authPlugin(userConfig = {}) {
112
119
  if (!user) return config.onUnauthorized(set)
113
120
  })
114
121
  .error(({ error, set }) => {
115
- if (String(error).includes('user.id') || String(error).includes('of null')) {
122
+ const errorStr = String(error)
123
+ if (errorStr.includes('user.id') || errorStr.includes('of null') || errorStr.includes('of undefined')) {
116
124
  set.status = 401
117
- return 'Sessão inválida ou expirada.'
125
+ set.headers['Content-Type'] = 'application/json'
126
+ return {
127
+ success: false,
128
+ error: {
129
+ code: 'UNAUTHORIZED',
130
+ message: 'Sessão inválida ou expirada. Por favor, faça login novamente.',
131
+ },
132
+ }
118
133
  }
119
134
  })
120
135
  .group(config.prefix, app =>