remove result of user creation
This commit is contained in:
@@ -1,67 +1,63 @@
|
||||
import { Router } from 'express';
|
||||
import { UserDto } from '../dto/user.dto';
|
||||
import { AuthService } from '../service/auth.service';
|
||||
import { UserService } from '../service/user.service';
|
||||
import { Router } from "express";
|
||||
import { AuthService } from "../service/auth.service";
|
||||
import { UserService } from "../service/user.service";
|
||||
|
||||
const router = Router();
|
||||
export const UserRoutes = router;
|
||||
|
||||
export const apiNamespace = '/users'
|
||||
export const apiNamespace = "/users";
|
||||
|
||||
router.post(apiNamespace, (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
|
||||
UserService.create({
|
||||
email,
|
||||
password
|
||||
}).then(user => {
|
||||
const respose: UserDto = {
|
||||
id: user.id,
|
||||
email: user.email
|
||||
}
|
||||
|
||||
res.json(respose);
|
||||
}).catch(err => {
|
||||
res.status(422).json({
|
||||
error: err.message
|
||||
});
|
||||
password,
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(422).json({
|
||||
error: err.message,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
router.post(`${apiNamespace}/sign_in`, async (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
|
||||
const user = await UserService.findByEmail(email)
|
||||
const user = await UserService.findByEmail(email);
|
||||
|
||||
const isPasswordValid = await AuthService.isUserPasswordValid(user, password)
|
||||
const isPasswordValid = await AuthService.isUserPasswordValid(user, password);
|
||||
|
||||
if (isPasswordValid) {
|
||||
const token = await AuthService.createSession(user)
|
||||
const token = await AuthService.createSession(user);
|
||||
|
||||
res.json({
|
||||
auth: true,
|
||||
token
|
||||
})
|
||||
token,
|
||||
});
|
||||
} else {
|
||||
res.status(500).json({
|
||||
auth: false,
|
||||
token: null,
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
router.delete(`${apiNamespace}/sign_out`, async (req, res) => {
|
||||
const token = req.headers['x-access-token']
|
||||
const token = req.headers["x-access-token"];
|
||||
|
||||
if (typeof token === 'string') {
|
||||
await AuthService.destoySession(token)
|
||||
if (typeof token === "string") {
|
||||
await AuthService.destoySession(token);
|
||||
|
||||
res.status(204).json({
|
||||
success: true
|
||||
})
|
||||
success: true,
|
||||
});
|
||||
} else {
|
||||
res.status(422).json({
|
||||
success: false
|
||||
})
|
||||
success: false,
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user