Skip to content
Snippets Groups Projects
Commit 3948f2ca authored by Hugo Brua's avatar Hugo Brua Committed by LAFORÊT Nicolas
Browse files

:pencil: get user emain from cookie

parent 80e6df8c
Branches
1 merge request!4Add CI deployment
......@@ -4,13 +4,12 @@ import {
} from "react-router-dom";
import { useAuth } from "./useAuth";
import { read_cookie } from 'sfcookies';
function RequireAuth({ children }: { children: JSX.Element }) {
let auth = useAuth();
let location = useLocation();
if (read_cookie('user').length === 0 && !auth.user) {
if (!auth.user) {
// Redirect them to the /login page, but save the current location they were
// trying to go to when they were redirected. This allows us to send them
// along to that page after they login, which is a nicer user experience
......
import React from 'react';
import { AuthContext } from './AuthContext';
import { read_cookie } from 'sfcookies';
function useAuth() {
return React.useContext(AuthContext);
let auth = React.useContext(AuthContext);
if(read_cookie('user').length !== 0)
auth.user = read_cookie('user');
return auth;
}
export { useAuth };
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment