2964c1e448
* Removed 'react-router-dom' as no longer needed Linked to: * news-server v1.7.4 * auth-server v1.8.10 * chat-server v1.5.4
29 lines
718 B
React
29 lines
718 B
React
import React, { useContext, useRef } from 'react';
|
|
import { Link } from 'react-router';
|
|
|
|
import { TokenContext } from '../../utilities/token-provider';
|
|
|
|
//TODO: make this an ACTUAL BUTTON
|
|
const Logout = () => {
|
|
const authTokens = useContext(TokenContext);
|
|
|
|
return (
|
|
<>
|
|
{ /* Logout logs you out of the server too */ }
|
|
<Link to='/' onClick={async () => {
|
|
const result = await authTokens.tokenFetch(`${process.env.AUTH_URI}/auth/logout`, { //NOTE: this gets overwritten as a bugfix
|
|
method: 'DELETE'
|
|
});
|
|
|
|
//any problems?
|
|
if (!result.ok) {
|
|
console.error(await result.text());
|
|
} else {
|
|
authTokens.setAccessToken('');
|
|
}
|
|
}}>Logout</Link>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Logout; |