1import React, { useState, useEffect } from 'react';
2import { Provider } from 'urql';
3
4import client from './client';
5
6import { getToken, saveAuthData } from './authStore';
7import Profile from './pages/Profile';
8import LoginForm from './pages/LoginForm';
9
10const Home = () => {
11 const [isLoggedIn, setIsLoggedIn] = useState(false);
12
13 const onLoginSuccess = auth => {
14 saveAuthData(auth);
15 setIsLoggedIn(true);
16 };
17
18 useEffect(() => {
19 if (getToken()) {
20 setIsLoggedIn(true);
21 }
22 }, []);
23
24 return isLoggedIn ? (
25 <Profile />
26 ) : (
27 <LoginForm onLoginSuccess={onLoginSuccess} />
28 );
29};
30
31function App() {
32 return (
33 <Provider value={client}>
34 <Home />
35 </Provider>
36 );
37}
38
39export default App;