From 700edc8e734fa74ab045500284711cd587580215 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson <93477693+innocuous-symmetry@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:14:46 -0600 Subject: [PATCH] wrapup --- client/src/util/apiUtils.tsx | 4 ++-- server/auth/index.ts | 4 ---- server/routes/auth.ts | 11 +++++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/client/src/util/apiUtils.tsx b/client/src/util/apiUtils.tsx index ad106e0..100f961 100644 --- a/client/src/util/apiUtils.tsx +++ b/client/src/util/apiUtils.tsx @@ -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) => { diff --git a/server/auth/index.ts b/server/auth/index.ts index 9c46c19..e9a4f01 100644 --- a/server/auth/index.ts +++ b/server/auth/index.ts @@ -56,10 +56,6 @@ export default class AuthService { } } - async logout() { - - } - // methods for Google OAuth async googleRegister() { diff --git a/server/routes/auth.ts b/server/routes/auth.ts index 1b09bad..0c90a29 100644 --- a/server/routes/auth.ts +++ b/server/routes/auth.ts @@ -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 {