mirror of
https://github.com/coder/coder.git
synced 2026-10-24 01:26:25 +08:00
This just implements a basic sign-in flow, using the new endpoints in #29 :  This brings over several dependencies that are necessary: - `formik` - `yep` Ports over some v1 code to bootstrap it: - `FormTextField` - `PasswordField` - `CoderIcon` And implements basic sign-in: Fixes #37 Fixes #43 This does not implement it navbar integration (importantly - there is no way to sign out yet, unless you manually delete your `session_token`). I'll do that in the next PR - figured this was big enough to get reviewed.
24 lines
461 B
TypeScript
24 lines
461 B
TypeScript
interface LoginResponse {
|
|
session_token: string
|
|
}
|
|
|
|
export const login = async (email: string, password: string): Promise<LoginResponse> => {
|
|
const response = await fetch("/api/v2/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
email,
|
|
password,
|
|
}),
|
|
})
|
|
|
|
const body = await response.json()
|
|
if (!response.ok) {
|
|
throw new Error(body.message)
|
|
}
|
|
|
|
return body
|
|
}
|