@rudderjs/auth 4.0.1 → 4.0.3

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 CHANGED
@@ -27,18 +27,18 @@ export default {
27
27
  }
28
28
 
29
29
  // bootstrap/providers.ts
30
- import { session } from '@rudderjs/session'
31
- import { hash } from '@rudderjs/hash'
32
- import { authProvider } from '@rudderjs/auth'
30
+ import { SessionProvider } from '@rudderjs/session'
31
+ import { HashProvider } from '@rudderjs/hash'
32
+ import { AuthProvider } from '@rudderjs/auth'
33
33
 
34
34
  export default [
35
- session(configs.session),
36
- hash(configs.hash),
37
- authProvider(configs.auth),
35
+ SessionProvider,
36
+ HashProvider,
37
+ AuthProvider,
38
38
  ]
39
39
  ```
40
40
 
41
- > `authProvider()` is the service-provider factory.
41
+ > `AuthProvider` is the service-provider class — list it directly in the providers array.
42
42
  > `auth()` (lowercase) is the per-request helper — see below.
43
43
 
44
44
  ## Usage
@@ -65,7 +65,7 @@ Route.get('/profile', async (req) => {
65
65
  })
66
66
  ```
67
67
 
68
- **No per-route wiring needed on web routes.** `authProvider()` auto-installs
68
+ **No per-route wiring needed on web routes.** `AuthProvider` auto-installs
69
69
  `AuthMiddleware` on the `web` route group during `boot()`, so every request
70
70
  matched by `withRouting({ web })` has the auth context populated before your
71
71
  handler runs.
@@ -107,7 +107,7 @@ Route.get('/login', showLoginPage, [RequireGuest('/')])
107
107
  import { AuthMiddleware } from '@rudderjs/auth'
108
108
  ```
109
109
 
110
- **You don't normally attach this on web routes.** `authProvider()` already
110
+ **You don't normally attach this on web routes.** `AuthProvider` already
111
111
  installs `AuthMiddleware()` on the `web` route group, so `req.user` and `auth()`
112
112
  work automatically on every web request. Reach for it manually in two cases:
113
113
 
@@ -172,6 +172,8 @@ The `EloquentUserProvider` auto-wraps ORM model records with these methods (mapp
172
172
 
173
173
  Ships React views for Login, Register, ForgotPassword, ResetPassword under `views/react/`. `create-rudder-app` vendors them into `app/Views/Auth/` at scaffold time so the app owns the files from day one and can edit them freely.
174
174
 
175
+ The views POST credentials with an `X-CSRF-Token` header read via `getCsrfToken()` from `@rudderjs/middleware`, so they work with `CsrfMiddleware` on the web group out of the box. `@rudderjs/middleware` is already a dep of any standard RudderJS app via the bootstrap pattern.
176
+
175
177
  To re-vendor manually (e.g. after upgrading this package):
176
178
 
177
179
  ```bash
@@ -46,7 +46,10 @@ Auth delegates hashing to `@rudderjs/hash`. The hash provider **must** be regist
46
46
 
47
47
  ```ts
48
48
  // bootstrap/providers.ts
49
- export default [hash(configs.hash), auth(configs.auth), ...]
49
+ import { HashProvider } from '@rudderjs/hash'
50
+ import { AuthProvider } from '@rudderjs/auth'
51
+
52
+ export default [HashProvider, AuthProvider]
50
53
  ```
51
54
 
52
55
  The `EloquentUserProvider` calls `hashCheck(plain, hashed)` internally during `validateCredentials()`.
@@ -115,7 +118,7 @@ class PostPolicy extends Policy {
115
118
 
116
119
  ```ts
117
120
  // Provider factory
118
- import { auth } from '@rudderjs/auth'
121
+ import { AuthProvider } from '@rudderjs/auth'
119
122
 
120
123
  // Middleware
121
124
  import { AuthMiddleware, RequireAuth, EnsureEmailIsVerified } from '@rudderjs/auth'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rudderjs/auth",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "rudderjs": {
5
5
  "provider": "AuthProvider",
6
6
  "stage": "infrastructure",
@@ -44,14 +44,14 @@
44
44
  "./package.json": "./package.json"
45
45
  },
46
46
  "dependencies": {
47
- "@rudderjs/contracts": "^1.1.0",
48
- "@rudderjs/core": "^1.0.0"
47
+ "@rudderjs/contracts": "^1.2.0",
48
+ "@rudderjs/core": "^1.1.2"
49
49
  },
50
50
  "peerDependencies": {
51
- "@rudderjs/session": "^1.0.1",
52
- "@rudderjs/router": "^1.0.0",
53
- "@rudderjs/view": "^1.0.0",
54
- "@rudderjs/hash": "^1.0.0"
51
+ "@rudderjs/hash": "^1.0.1",
52
+ "@rudderjs/router": "^1.1.2",
53
+ "@rudderjs/session": "^1.0.3",
54
+ "@rudderjs/view": "^1.0.1"
55
55
  },
56
56
  "peerDependenciesMeta": {
57
57
  "@rudderjs/hash": {
@@ -71,10 +71,10 @@
71
71
  "@types/node": "^20.0.0",
72
72
  "reflect-metadata": "^0.2.2",
73
73
  "typescript": "^5.4.0",
74
- "@rudderjs/hash": "^1.0.0",
75
- "@rudderjs/router": "^1.0.0",
76
- "@rudderjs/session": "^1.0.1",
77
- "@rudderjs/view": "^1.0.0"
74
+ "@rudderjs/hash": "^1.0.1",
75
+ "@rudderjs/router": "^1.1.2",
76
+ "@rudderjs/session": "^1.0.3",
77
+ "@rudderjs/view": "^1.0.1"
78
78
  },
79
79
  "author": "Suleiman Shahbari",
80
80
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import '@/index.css'
2
2
  import { useState } from 'react'
3
+ import { getCsrfToken } from '@rudderjs/middleware'
3
4
 
4
5
  // URL this view is served at — see Login.tsx for rationale.
5
6
  export const route = '/forgot-password'
@@ -28,7 +29,10 @@ export default function ForgotPassword(props: ForgotPasswordProps) {
28
29
  try {
29
30
  const res = await fetch(submitUrl, {
30
31
  method: 'POST',
31
- headers: { 'Content-Type': 'application/json' },
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ 'X-CSRF-Token': getCsrfToken(),
35
+ },
32
36
  body: JSON.stringify({ email, redirectTo: resetPasswordUrl }),
33
37
  })
34
38
  if (res.ok) {
@@ -1,6 +1,7 @@
1
1
  import '@/index.css'
2
2
  import { useState } from 'react'
3
3
  import { navigate } from 'vike/client/router'
4
+ import { getCsrfToken } from '@rudderjs/middleware'
4
5
 
5
6
  // URL this view is served at — MUST match the controller route registered
6
7
  // by registerAuthRoutes() in the consumer project. If you override
@@ -32,7 +33,10 @@ export default function Login(props: LoginProps) {
32
33
  setLoading(true)
33
34
  const res = await fetch(submitUrl, {
34
35
  method: 'POST',
35
- headers: { 'Content-Type': 'application/json' },
36
+ headers: {
37
+ 'Content-Type': 'application/json',
38
+ 'X-CSRF-Token': getCsrfToken(),
39
+ },
36
40
  body: JSON.stringify({ email, password }),
37
41
  })
38
42
  if (res.ok) {
@@ -1,6 +1,7 @@
1
1
  import '@/index.css'
2
2
  import { useState } from 'react'
3
3
  import { navigate } from 'vike/client/router'
4
+ import { getCsrfToken } from '@rudderjs/middleware'
4
5
 
5
6
  // URL this view is served at — see Login.tsx for rationale.
6
7
  export const route = '/register'
@@ -28,7 +29,10 @@ export default function Register(props: RegisterProps) {
28
29
  setLoading(true)
29
30
  const res = await fetch(submitUrl, {
30
31
  method: 'POST',
31
- headers: { 'Content-Type': 'application/json' },
32
+ headers: {
33
+ 'Content-Type': 'application/json',
34
+ 'X-CSRF-Token': getCsrfToken(),
35
+ },
32
36
  body: JSON.stringify({ name, email, password }),
33
37
  })
34
38
  if (res.ok) {
@@ -1,5 +1,6 @@
1
1
  import '@/index.css'
2
2
  import { useState, useEffect } from 'react'
3
+ import { getCsrfToken } from '@rudderjs/middleware'
3
4
 
4
5
  // URL this view is served at — see Login.tsx for rationale.
5
6
  export const route = '/reset-password'
@@ -45,7 +46,10 @@ export default function ResetPassword(props: ResetPasswordProps) {
45
46
  try {
46
47
  const res = await fetch(submitUrl, {
47
48
  method: 'POST',
48
- headers: { 'Content-Type': 'application/json' },
49
+ headers: {
50
+ 'Content-Type': 'application/json',
51
+ 'X-CSRF-Token': getCsrfToken(),
52
+ },
49
53
  body: JSON.stringify({ token, email, newPassword: password }),
50
54
  })
51
55
  if (res.ok) {