chore: rewrite /login page for OAuth, write createUser for the database
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// TODO: move to `shared/` and distinguish client and server (fix imports)
|
||||
|
||||
export function prependBaseUrl(route: string) {
|
||||
return import.meta.env.BASE_URL + (route.startsWith('/') ? route.substring(1) : route)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ type UserFunctionsHook = () => {
|
||||
logout: () => Promise<void>
|
||||
}
|
||||
|
||||
// TODO: remove login as it is deprecated
|
||||
|
||||
export const useUserFunctions: UserFunctionsHook = () => {
|
||||
const login = async (username: string) => {
|
||||
await fetch(prependBaseUrl(`/api/login`), {
|
||||
|
||||
@@ -1,37 +1,13 @@
|
||||
import { route } from 'preact-router'
|
||||
|
||||
import { useState } from 'preact/hooks'
|
||||
import { prependBaseUrl } from '../api.js'
|
||||
import { Header } from '../components/Header.jsx'
|
||||
import { useUserFunctions } from '../hooks/useCurrentUser.js'
|
||||
|
||||
export const LoginPage = () => {
|
||||
const [username, setUsername] = useState('')
|
||||
const { login } = useUserFunctions()
|
||||
|
||||
const handleLogin = async () => {
|
||||
await login(username)
|
||||
route(prependBaseUrl('/'))
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<main class="page-login">
|
||||
<div class="subtitle">Accedi</div>
|
||||
<div class="form">
|
||||
<label for="login-username">Username</label>
|
||||
<input
|
||||
id="login-username"
|
||||
type="text"
|
||||
value={username}
|
||||
onInput={e => setUsername(e.target instanceof HTMLInputElement ? e.target.value : '')}
|
||||
onKeyDown={e => e.key === 'Enter' && handleLogin()}
|
||||
/>
|
||||
|
||||
<div class="fill">
|
||||
<button onClick={handleLogin}>Accedi</button>
|
||||
</div>
|
||||
<div class="fill">
|
||||
<a class="button" role="button" href={prependBaseUrl('/auth/redirect')} data-native>Accedi con Ateneo</a>
|
||||
</div>
|
||||
</main>
|
||||
</>
|
||||
|
||||
@@ -119,7 +119,7 @@ input[type='text'] {
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
button, .button {
|
||||
cursor: pointer;
|
||||
|
||||
font-family: 'Lato';
|
||||
|
||||
Reference in New Issue
Block a user