generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17a0131
commit 80b10b3
Showing
8 changed files
with
90 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
import React, { useState } from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import Game from './components/Game/Game'; | ||
import { isLogged } from './services/auth-service'; | ||
import { loginWithToken } from './services/auth-service'; | ||
import Authentication from './components/auth/Authentication'; | ||
|
||
|
||
|
||
import { useUserStore } from './stores/user-store'; | ||
|
||
function App() { | ||
const [isLoggedState, setIsLoggedState] = useState(isLogged()); | ||
|
||
const user = useUserStore(state => state.user); | ||
|
||
useEffect(() => { | ||
loginWithToken(); | ||
}, []); | ||
|
||
if (!isLoggedState) { | ||
return <Authentication setIsLoggedState={setIsLoggedState}/> | ||
if (user == null) { | ||
return <Authentication/> | ||
} | ||
else { | ||
return <Game /> | ||
} | ||
return <Game /> | ||
|
||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
import {create} from 'zustand'; | ||
import { JwtPayload } from '../services/auth-service'; | ||
|
||
interface UserState { | ||
user: JwtPayload | null, | ||
setUser: (user : JwtPayload) => void, | ||
logout: () => void, | ||
} | ||
|
||
|
||
export const useUserStore = create<UserState>((set) => ({ | ||
user: null, | ||
setUser: (user) => set({user}), | ||
logout: () => set({user:null}) | ||
})); |