@maximemrf/adonisjs-jwt 0.4.0 → 0.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/README.md +6 -1
- package/build/src/define_config.d.ts +1 -0
- package/build/src/define_config.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ import { sessionGuard, sessionUserProvider } from '@adonisjs/auth/session'
|
|
|
38
38
|
import { jwtGuard } from '@maximemrf/adonisjs-jwt/jwt_config'
|
|
39
39
|
import { JwtGuardUser, BaseJwtContent } from '@maximemrf/adonisjs-jwt/types'
|
|
40
40
|
import User from '#models/user'
|
|
41
|
+
import env from '#start/env'
|
|
41
42
|
|
|
42
43
|
interface JwtContent extends BaseJwtContent {
|
|
43
44
|
email: string
|
|
@@ -61,6 +62,10 @@ const authConfig = defineConfig({
|
|
|
61
62
|
tokenExpiresIn: '1h',
|
|
62
63
|
// if you want to use cookies for the authentication instead of the bearer token (optional)
|
|
63
64
|
useCookies: true,
|
|
65
|
+
// secret is the secret used to sign the token, it can be optional, by default it uses the application key
|
|
66
|
+
// you can use a env variable like JWT_SECRET or set it directly with a string
|
|
67
|
+
// if you don't have specific needs, please discard this option
|
|
68
|
+
secret: env.get('JWT_SECRET'),
|
|
64
69
|
provider: sessionUserProvider({
|
|
65
70
|
model: () => import('#models/user'),
|
|
66
71
|
}),
|
|
@@ -99,7 +104,7 @@ useCookies: true
|
|
|
99
104
|
|
|
100
105
|
If you just want to use jwt with the bearer token no need to set `useCookies` to `false` you can just remove it.
|
|
101
106
|
|
|
102
|
-
##
|
|
107
|
+
## Authentication
|
|
103
108
|
|
|
104
109
|
To make a protected route, you have to use the `auth` middleware with the `jwt` guard.
|
|
105
110
|
|
|
@@ -8,5 +8,6 @@ export declare function jwtGuard<UserProvider extends JwtUserProviderContract<un
|
|
|
8
8
|
tokenName?: string;
|
|
9
9
|
tokenExpiresIn?: number | StringValue;
|
|
10
10
|
useCookies?: boolean;
|
|
11
|
+
secret?: string;
|
|
11
12
|
content: <T>(user: JwtGuardUser<T>) => Record<string | number, any>;
|
|
12
13
|
}): GuardConfigProvider<(ctx: HttpContext) => JwtGuard<UserProvider>>;
|
|
@@ -4,7 +4,7 @@ export function jwtGuard(config) {
|
|
|
4
4
|
async resolver(_, app) {
|
|
5
5
|
const appKey = app.config.get('app.appKey').release();
|
|
6
6
|
const options = {
|
|
7
|
-
secret: appKey,
|
|
7
|
+
secret: config.secret ?? appKey,
|
|
8
8
|
tokenName: config.tokenName,
|
|
9
9
|
expiresIn: config.tokenExpiresIn,
|
|
10
10
|
useCookies: config.useCookies,
|
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.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.6.0"
|
|
7
7
|
},
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
24
|
"lint": "eslint .",
|
|
25
25
|
"format": "prettier --write .",
|
|
26
|
-
"quick:test": "node --import
|
|
26
|
+
"quick:test": "node --import=ts-node-maintained/register/esm --enable-source-maps --experimental-import-meta-resolve bin/test.ts --force-exit",
|
|
27
27
|
"pretest": "npm run lint",
|
|
28
28
|
"test": "c8 npm run quick:test",
|
|
29
29
|
"prebuild": "npm run lint && npm run clean",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"np": "^10.0.0",
|
|
54
54
|
"prettier": "^3.5.3",
|
|
55
55
|
"timekeeper": "^2.3.1",
|
|
56
|
-
"ts-node": "^10.9.
|
|
56
|
+
"ts-node-maintained": "^10.9.5",
|
|
57
57
|
"typescript": "~5.8"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|