-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
45 lines (37 loc) · 1017 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
33
34
35
36
37
38
39
40
41
42
43
44
45
import dotenv from "dotenv";
import createSession from "./createSession.js";
import {
createAppServer,
LowDBUserDao,
createLowDb,
} from "@stanlemon/server-with-auth";
import Joi from "joi";
dotenv.config();
const port = process.env.PORT || 3000;
const schema = Joi.object({
name: Joi.string().required().label("Name"),
email: Joi.string().email().required().label("Email"),
username: Joi.string().required().label("Username"),
password: Joi.string().required().min(8).max(64).label("Password"),
});
const db = createLowDb();
const dao = new LowDBUserDao(db);
const app = createAppServer({
port,
webpack: "http://localhost:8080",
secure: ["/api/"],
schema,
dao,
});
app.get("/api/session", async (req, res, next) => {
const user = await dao.getUserByUsername(req.user.username);
const session = await createSession(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET,
user.username
);
res.json({
...session,
});
});