-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathusers.js
47 lines (42 loc) · 1.16 KB
/
users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// @flow
import { createResource } from "@brigad/redux-rest-easy"
import { normalize, schema } from "normalizr"
import { customerSelfServiceBackend } from "../config"
const usersSchema = new schema.Entity("users", undefined, {
idAttribute: "email",
})
const users = createResource("users")({
signupUser: {
method: "POST",
url: `${customerSelfServiceBackend}/auth/signup`,
normalizer: data => {
return normalize(data, usersSchema)
},
networkHelpers: {
handleError: async (err, dispatch) => {
// Overrides the default error handler so that we don't consume
// the response body more than once.
},
},
},
loginUser: {
method: "POST",
url: `${customerSelfServiceBackend}/auth`,
normalizer: data => {
return normalize(data, usersSchema)
},
networkHelpers: {
handleError: async (err, dispatch) => {
// Overrides the default error handler so that we don't consume
// the response body more than once.
},
},
},
})
const {
actions: {
signupUser: { perform: signupUser },
loginUser: { perform: loginUser },
},
} = users
export { signupUser, loginUser }