62 lines
1.2 KiB
TypeScript
62 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import React, {ChangeEventHandler, useState} from 'react';
|
|
import { createClient } from '@supabase/supabase-js';
|
|
|
|
interface State {
|
|
username: string;
|
|
password: string;
|
|
}
|
|
|
|
async function doLogin(loginInfo: State) {
|
|
const client = createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL ?? '',
|
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?? ''
|
|
);
|
|
|
|
|
|
const { data, error } = await client.auth.signInWithPassword({
|
|
email: loginInfo.username,
|
|
password: loginInfo.password
|
|
});
|
|
|
|
console.log(data);
|
|
console.log(error);
|
|
|
|
alert('logged in(?)');
|
|
}
|
|
|
|
export default function Login() {
|
|
const [loginInfo , setLoginInfo] = useState({
|
|
username: '',
|
|
password: ''
|
|
});
|
|
|
|
|
|
const inputHandler: ChangeEventHandler<HTMLInputElement> =
|
|
(e) => {
|
|
setLoginInfo(prevState => ({
|
|
...prevState,
|
|
[e.target.name]: e.target.value,
|
|
}));
|
|
};
|
|
|
|
return (
|
|
<div>
|
|
<div>Username</div>
|
|
<div>
|
|
<input id="username" type="text" name="username" onChange={inputHandler}/>
|
|
</div>
|
|
|
|
<div>Password</div>
|
|
<div>
|
|
<input id="password" type="password" name="password" onChange={inputHandler}/>
|
|
</div>
|
|
|
|
<div>
|
|
<input type="submit" value="Login" onClick={() => doLogin(loginInfo)} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|