-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (26 loc) · 910 Bytes
/
server.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
import { createServer, Model, Response } from "miragejs"
createServer({
models: {
users: Model
},
seeds(server) {
server.create("user", { id: "123", email: "[email protected]", password: "p123", name: "Bob" })
},
routes() {
this.namespace = "api"
this.logging = false
this.passthrough("https://firestore.googleapis.com/**")
this.post("/login", (schema, request) => {
const { email, password } = JSON.parse(request.requestBody)
const foundUser = schema.users.findBy({ email, password })
if (!foundUser) {
return new Response(401, {}, { message: "No user with those credentials found!" })
}
foundUser.password = undefined
return {
user: foundUser,
token: "Enjoy your pizza, here's your tokens."
}
})
}
})