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 () => { export const attemptLogout = async () => {
const response = await fetch(API + 'auth').then(response => response.json()); const result = await fetch(API + 'auth/logout', { method: "DELETE" }).then(response => response.json());
return response; return result;
} }
export const attemptRegister = async (data: IUser) => { export const attemptRegister = async (data: IUser) => {

View File

@@ -56,10 +56,6 @@ export default class AuthService {
} }
} }
async logout() {
}
// methods for Google OAuth // methods for Google OAuth
async googleRegister() { 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 { try {
if (req.session) req.session.destroy(); req.session.destroy((err) => {
res.sendStatus(200); if (err) throw err;
})
res.clearCookie('userid');
res.status(204).send({ success: true });
} catch(e) { } catch(e) {
next(e); next(e);
} }
})); });
router.post('/register', async (req, res, next) => { router.post('/register', async (req, res, next) => {
try { try {