@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 +18 -3
- package/dist/index.js +18 -3
- package/package.json +1 -1
- package/src/index.js +18 -3
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =>
|