diff options
| author | Paweł Bernaciak <pawelbernaciak@zohomail.eu> | 2023-10-21 11:55:50 +0200 |
|---|---|---|
| committer | Paweł Bernaciak <pawelbernaciak@zohomail.eu> | 2023-10-21 11:55:50 +0200 |
| commit | 2ef3bdcd89731c1ed9cb7528181d19b2d9169bb5 (patch) | |
| tree | 9aa6d907425d3609ab9ae4affcf5b86ef794a6da /frontend/src/App.tsx | |
| parent | 12fef7cbaf2073f9cc349ed765ea140be0259d8e (diff) | |
Add basic frontend to test login
Diffstat (limited to 'frontend/src/App.tsx')
| -rw-r--r-- | frontend/src/App.tsx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx new file mode 100644 index 0000000..996a794 --- /dev/null +++ b/frontend/src/App.tsx @@ -0,0 +1,58 @@ +import React from 'react'; +import { CredentialResponse, GoogleLogin } from '@react-oauth/google'; + +interface LoginResponse { + id: number +} + +interface User { + id: Number, + elements: Element[], +} + +interface Element { + id: Number, + userId: Number, + name: string, + state: ElementState, +} + +enum ElementState { + HasColor, + HasIcon, +} + +function App() { + const responseMessage = async (googleResponse: CredentialResponse) => { + console.log(googleResponse); + const url: string = "/auth/login"; + const body = { + "googleToken": googleResponse.credential + }; + + const response = await fetch(url, { + method: "POST", + credentials: "include", + mode: "cors", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(body), + }); + if (!response.ok) { + console.log("Backend conection problem"); + return; + } + + const user = await response.json() as LoginResponse; + console.log(user); + }; + + return ( + <div className="App"> + <GoogleLogin onSuccess={responseMessage} /> + </div> + ); +} + +export default App; |
