This commit is contained in:
Mikayla Dobson
2022-11-21 18:14:46 -06:00
parent 5ddd01a537
commit 700edc8e73
3 changed files with 9 additions and 10 deletions

View File

@@ -24,8 +24,8 @@ export const attemptLogin = async (data: IUserAuth) => {
}
export const attemptLogout = async () => {
const response = await fetch(API + 'auth').then(response => response.json());
return response;
const result = await fetch(API + 'auth/logout', { method: "DELETE" }).then(response => response.json());
return result;
}
export const attemptRegister = async (data: IUser) => {

View File

@@ -56,10 +56,6 @@ export default class AuthService {
}
}
async logout() {
}
// methods for Google OAuth
async googleRegister() {

View File

@@ -39,14 +39,17 @@ export const authRoute = (app: Express, passport: PassportStatic) => {
}
})
router.post('/logout', passport.authenticate('local', async (req, res, next) => {
router.delete('/logout', async (req, res, next) => {
try {
if (req.session) req.session.destroy();
res.sendStatus(200);
req.session.destroy((err) => {
if (err) throw err;
})
res.clearCookie('userid');
res.status(204).send({ success: true });
} catch(e) {
next(e);
}
}));
});
router.post('/register', async (req, res, next) => {
try {