defined auth route on api, attempting to connect to front end

This commit is contained in:
Mikayla Dobson
2022-11-21 11:22:00 -06:00
parent 1b08598799
commit 57a16e429e
10 changed files with 80 additions and 53 deletions

31
server/routes/auth.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Express, Router } from "express"
import { PassportStatic } from "passport";
import { IUser, IUserAuth } from "../schemas";
import AuthService from "../auth";
const AuthInstance = new AuthService();
const router = Router();
export const authRoute = (app: Express, passport: PassportStatic) => {
app.use('/auth', router);
router.post('/login', passport.authenticate('local'), async (req, res, next) => {
try {
const data: IUserAuth = req.body;
const response = await AuthInstance.login(data);
res.status(200).send(response);
} catch(e) {
next(e);
}
})
router.post('/register', async (req, res, next) => {
try {
const data: IUser = req.body;
const response = await AuthInstance.register(data);
res.status(200).send(response);
} catch(e) {
next(e);
}
})
}