@rudderjs/auth 4.0.1 → 4.0.2
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
|
@@ -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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rudderjs/auth",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"rudderjs": {
|
|
5
5
|
"provider": "AuthProvider",
|
|
6
6
|
"stage": "infrastructure",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"@rudderjs/core": "^1.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@rudderjs/session": "^1.0.1",
|
|
52
51
|
"@rudderjs/router": "^1.0.0",
|
|
53
|
-
"@rudderjs/
|
|
54
|
-
"@rudderjs/
|
|
52
|
+
"@rudderjs/hash": "^1.0.0",
|
|
53
|
+
"@rudderjs/session": "^1.0.2",
|
|
54
|
+
"@rudderjs/view": "^1.0.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependenciesMeta": {
|
|
57
57
|
"@rudderjs/hash": {
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"typescript": "^5.4.0",
|
|
74
74
|
"@rudderjs/hash": "^1.0.0",
|
|
75
75
|
"@rudderjs/router": "^1.0.0",
|
|
76
|
-
"@rudderjs/session": "^1.0.
|
|
76
|
+
"@rudderjs/session": "^1.0.2",
|
|
77
77
|
"@rudderjs/view": "^1.0.0"
|
|
78
78
|
},
|
|
79
79
|
"author": "Suleiman Shahbari",
|
|
@@ -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: {
|
|
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) {
|
package/views/react/Login.tsx
CHANGED
|
@@ -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: {
|
|
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) {
|
package/views/react/Register.tsx
CHANGED
|
@@ -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: {
|
|
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: {
|
|
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) {
|