Skip to content

Commit

Permalink
adding api route handlers as proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
ddmuzyk committed Feb 26, 2024
1 parent a8e4927 commit 3666e69
Show file tree
Hide file tree
Showing 10 changed files with 1,083 additions and 16 deletions.
14 changes: 13 additions & 1 deletion components/poker/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ const Login = () => {
const [email, setEmail] = useState<string>('');
const [password, setPassword] = useState<string>('');

const tryLogin = async (email: string, password: string) => {
const res = await fetch('/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({email, password})
})
const data = await res.json()
console.log(data)
}

return (
<form className={styles.form}>
<input onChange={(e) => setEmail(e.target.value)} placeholder='Email' className={styles.input} type="email"/>
<input onChange={(e) => setPassword(e.target.value)} placeholder='Password' className={styles.input} type="password"/>
<button onClick={() => {login(email, password)}} type='button' className={styles.button}>Log in</button>
<button onClick={async () => {await tryLogin(email, password)}} type='button' className={styles.button}>Log in</button>
</form>
)
}
Expand Down
7 changes: 3 additions & 4 deletions lib/poker/poker-logic/functions/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ export const login = async (email: string, password: string) => {
headers: {
'Content-Type': 'application/json'
},
credentials: 'include',
body: JSON.stringify({email, password})
})
const data = await response.json()
if (data === 'Logged in') {
window.location.href = '/game/poker'
if (data.accessToken) {
return data
}
} catch (error) {
console.log(error)
return 'error'
}
}
Loading

0 comments on commit 3666e69

Please sign in to comment.