Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions apps/web/app/routes/auth/login.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"use client";

import { useState } from "react";
import type { FC } from "react";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { SiGoogle, SiOkta } from "@icons-pack/react-simple-icons";
import { authClient } from "~/api/auth-client";
import { useAuthConfig } from "~/api/auth-config";
import { Alert, AlertDescription } from "~/components/ui/alert";
import { Button } from "~/components/ui/button";
import {
Card,
Expand Down Expand Up @@ -48,7 +51,8 @@ const signInEmailPasswordSchema = z.object({
password: z.string(),
});

function LoginEmailPassword() {
const LoginEmailPassword: FC = () => {
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const form = useForm<z.infer<typeof signInEmailPasswordSchema>>({
resolver: zodResolver(signInEmailPasswordSchema),
defaultValues: {
Expand All @@ -57,17 +61,29 @@ function LoginEmailPassword() {
},
});

const onSubmit = (data: z.infer<typeof signInEmailPasswordSchema>) => {
void authClient.signIn.email({
const onSubmit = async (data: z.infer<typeof signInEmailPasswordSchema>) => {
setErrorMessage(null);
const { error } = await authClient.signIn.email({
...data,
rememberMe: true,
callbackURL: "/workspaces",
});
if (error)
setErrorMessage(
error.code === "INVALID_EMAIL_OR_PASSWORD" && error.message
? error.message
: "Failed to sign in",
);
};
Comment thread
jsingleton-dev marked this conversation as resolved.

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
{errorMessage && (
<Alert variant="destructive">
<AlertDescription>{errorMessage}</AlertDescription>
</Alert>
)}
<FormField
control={form.control}
name="email"
Expand Down Expand Up @@ -111,7 +127,7 @@ function LoginEmailPassword() {
</form>
</Form>
);
}
};

export default function Login() {
const authConfig = useAuthConfig();
Expand Down
Loading