logout
This commit is contained in:
parent
d1f737afdd
commit
9e9a4b3897
@ -7,6 +7,9 @@ const caller = (url = '/api') => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const API = {
|
const API = {
|
||||||
|
logout() {
|
||||||
|
return caller().post('/auth/logout');
|
||||||
|
},
|
||||||
login(data) {
|
login(data) {
|
||||||
return caller().post('/auth/login', data);
|
return caller().post('/auth/login', data);
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { createContext, useState, useContext } from 'react';
|
import { createContext, useState, useContext } from 'react';
|
||||||
|
import API from '../services/api';
|
||||||
|
|
||||||
const AuthContext = createContext();
|
const AuthContext = createContext();
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ const AuthProvider = ({ children }) => {
|
|||||||
const logout = () => {
|
const logout = () => {
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
window.location.href = '/auth';
|
window.location.href = '/auth';
|
||||||
|
API.logout();
|
||||||
};
|
};
|
||||||
|
|
||||||
const useAuth = () => useContext(AuthContext);
|
const useAuth = () => useContext(AuthContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user