@strav/jina 0.2.3 → 0.2.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/package.json +1 -1
- package/src/jina_manager.ts +30 -18
- package/src/types.ts +8 -0
package/package.json
CHANGED
package/src/jina_manager.ts
CHANGED
|
@@ -28,6 +28,11 @@ const DEFAULTS: JinaConfig = {
|
|
|
28
28
|
features: ['registration', 'login', 'logout', 'password-reset'],
|
|
29
29
|
prefix: '',
|
|
30
30
|
mode: 'session',
|
|
31
|
+
routes: {
|
|
32
|
+
aliases: {
|
|
33
|
+
auth: 'jina.auth'
|
|
34
|
+
}
|
|
35
|
+
},
|
|
31
36
|
rateLimit: {
|
|
32
37
|
login: { max: 5, window: 60 },
|
|
33
38
|
register: { max: 3, window: 60 },
|
|
@@ -135,61 +140,68 @@ export default class JinaManager {
|
|
|
135
140
|
return true
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
const
|
|
143
|
+
const config = JinaManager._config
|
|
144
|
+
const prefix = config.prefix
|
|
145
|
+
const authAlias = config.routes.aliases.auth
|
|
146
|
+
const subdomain = config.routes.subdomain
|
|
147
|
+
|
|
148
|
+
const middleware = config.mode === 'session' ? [session()] : []
|
|
139
149
|
|
|
140
|
-
|
|
150
|
+
router.group({ prefix, middleware, subdomain }, r => {
|
|
151
|
+
r.group({}, authRoutes).as(authAlias)
|
|
152
|
+
})
|
|
141
153
|
|
|
142
|
-
|
|
154
|
+
function authRoutes(r: Router): void {
|
|
143
155
|
if (enabled('registration')) {
|
|
144
|
-
r.post('/register', withMiddleware([guest(), JinaManager.rl('register')], registerHandler))
|
|
156
|
+
r.post('/register', withMiddleware([guest(), JinaManager.rl('register')], registerHandler)).as('register')
|
|
145
157
|
}
|
|
146
158
|
|
|
147
159
|
if (enabled('login')) {
|
|
148
|
-
r.post('/login', withMiddleware([guest(), JinaManager.rl('login')], loginHandler))
|
|
160
|
+
r.post('/login', withMiddleware([guest(), JinaManager.rl('login')], loginHandler)).as('login')
|
|
149
161
|
}
|
|
150
162
|
|
|
151
163
|
if (enabled('logout')) {
|
|
152
|
-
r.post('/logout', withMiddleware([auth()], logoutHandler))
|
|
164
|
+
r.post('/logout', withMiddleware([auth()], logoutHandler)).as('logout')
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
if (enabled('password-reset')) {
|
|
156
168
|
r.post(
|
|
157
169
|
'/forgot-password',
|
|
158
170
|
withMiddleware([guest(), JinaManager.rl('forgotPassword')], forgotPasswordHandler)
|
|
159
|
-
)
|
|
160
|
-
r.post('/reset-password', withMiddleware([guest()], resetPasswordHandler))
|
|
171
|
+
).as('forgot_password')
|
|
172
|
+
r.post('/reset-password', withMiddleware([guest()], resetPasswordHandler)).as('reset_password')
|
|
161
173
|
}
|
|
162
174
|
|
|
163
175
|
if (enabled('email-verification')) {
|
|
164
176
|
r.post(
|
|
165
177
|
'/email/send',
|
|
166
178
|
withMiddleware([auth(), JinaManager.rl('verifyEmail')], sendVerificationHandler)
|
|
167
|
-
)
|
|
168
|
-
r.get('/email/verify/:token', verifyEmailHandler)
|
|
179
|
+
).as('send_verification')
|
|
180
|
+
r.get('/email/verify/:token', verifyEmailHandler).as('verify_email')
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
if (enabled('two-factor')) {
|
|
172
|
-
r.post('/two-factor/enable', withMiddleware([auth(), confirmed()], enableTwoFactorHandler))
|
|
173
|
-
r.post('/two-factor/confirm', withMiddleware([auth()], confirmTwoFactorHandler))
|
|
174
|
-
r.delete('/two-factor', withMiddleware([auth(), confirmed()], disableTwoFactorHandler))
|
|
184
|
+
r.post('/two-factor/enable', withMiddleware([auth(), confirmed()], enableTwoFactorHandler)).as('enable_two_factor')
|
|
185
|
+
r.post('/two-factor/confirm', withMiddleware([auth()], confirmTwoFactorHandler)).as('confirm_two_factor')
|
|
186
|
+
r.delete('/two-factor', withMiddleware([auth(), confirmed()], disableTwoFactorHandler)).as('disable_two_factor')
|
|
175
187
|
r.post(
|
|
176
188
|
'/two-factor/challenge',
|
|
177
189
|
withMiddleware([JinaManager.rl('twoFactor')], twoFactorChallengeHandler)
|
|
178
|
-
)
|
|
190
|
+
).as('two_factor_challenge')
|
|
179
191
|
}
|
|
180
192
|
|
|
181
193
|
if (enabled('password-confirmation')) {
|
|
182
|
-
r.post('/confirm-password', withMiddleware([auth()], confirmPasswordHandler))
|
|
194
|
+
r.post('/confirm-password', withMiddleware([auth()], confirmPasswordHandler)).as('confirm_password')
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
if (enabled('update-password')) {
|
|
186
|
-
r.put('/password', withMiddleware([auth()], updatePasswordHandler))
|
|
198
|
+
r.put('/password', withMiddleware([auth()], updatePasswordHandler)).as('update_password')
|
|
187
199
|
}
|
|
188
200
|
|
|
189
201
|
if (enabled('update-profile')) {
|
|
190
|
-
r.put('/profile', withMiddleware([auth()], updateProfileHandler))
|
|
202
|
+
r.put('/profile', withMiddleware([auth()], updateProfileHandler)).as('update_profile')
|
|
191
203
|
}
|
|
192
|
-
}
|
|
204
|
+
}
|
|
193
205
|
}
|
|
194
206
|
|
|
195
207
|
/** Clear all state. For testing. */
|
package/src/types.ts
CHANGED
|
@@ -88,6 +88,14 @@ export interface JinaConfig {
|
|
|
88
88
|
features: Feature[]
|
|
89
89
|
prefix: string
|
|
90
90
|
mode: 'session' | 'token'
|
|
91
|
+
routes: {
|
|
92
|
+
/** Route group alias for authentication endpoints (e.g., 'jina.auth' or 'auth') */
|
|
93
|
+
aliases: {
|
|
94
|
+
auth: string
|
|
95
|
+
}
|
|
96
|
+
/** Optional subdomain for authentication routes */
|
|
97
|
+
subdomain?: string
|
|
98
|
+
}
|
|
91
99
|
rateLimit: {
|
|
92
100
|
login: RateLimitConfig
|
|
93
101
|
register: RateLimitConfig
|