-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.ts
More file actions
27 lines (24 loc) · 859 Bytes
/
Copy pathsignup.ts
File metadata and controls
27 lines (24 loc) · 859 Bytes
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
import { generateToken } from "./../../services/authenticator";
import { Request, Response } from "express";
import { connection } from "../../connection";
import { userTableName } from "../../data/TableName";
import { generateHash } from "../../services/hashManager";
import { generateId } from "../../services/idGenerator";
export async function signup(req: Request, res: Response): Promise<void> {
try {
const { name, email, password } = req.body;
const id: string = generateId();
const cypherPassword: string = generateHash(password);
const token: string = generateToken({ id });
await connection(userTableName).insert({
id,
name,
email,
password: cypherPassword,
});
res.send({ token });
} catch (error) {
console.log(error.message);
res.status(500).send("Internal server error");
}
}