mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the organization system.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
"use server";
|
||||
import { RegisterSchema } from "@/components/wrappers/auth/Register/register-form/register-form.schema";
|
||||
import { action } from "@/safe-actions";
|
||||
import { signUp } from "@/lib/auth/auth-client";
|
||||
import { db } from "@/db";
|
||||
import { user as drizzleUser } from "@/db/schema/01_user";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export const registerUserAction = action.schema(RegisterSchema).action(async ({ parsedInput }: { parsedInput: typeof RegisterSchema._type }) => {
|
||||
const [user] = await db.select().from(drizzleUser).where(eq(drizzleUser.email, parsedInput.email)).limit(1);
|
||||
|
||||
if (!user && parsedInput.password === parsedInput.confirmPassword) {
|
||||
const { data, error } = await signUp.email({
|
||||
email: parsedInput.email,
|
||||
password: parsedInput.password,
|
||||
name: parsedInput.name,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
return {
|
||||
data: data?.user,
|
||||
};
|
||||
}
|
||||
throw new Error("An error occured while creating user");
|
||||
});
|
||||
@@ -26,6 +26,7 @@ export const LoginForm = (props: loginFormProps) => {
|
||||
const form = useZodForm({
|
||||
schema: LoginSchema,
|
||||
});
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (values: LoginType) => {
|
||||
const { error } = await signIn.email(values, {
|
||||
|
||||
+15
-14
@@ -11,36 +11,37 @@ import { Input } from "@/components/ui/input";
|
||||
import { Form } from "@/components/ui/form";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TooltipProvider, TooltipTrigger, Tooltip, TooltipContent } from "@/components/ui/tooltip";
|
||||
import { RegisterSchema, RegisterType } from "@/components/wrappers/auth/Register/register-form/register-form.schema";
|
||||
import { registerUserAction } from "@/components/wrappers/auth/Register/register-form/register-form.action";
|
||||
import { RegisterSchema, RegisterType } from "@/components/wrappers/auth/register/register-form/register-form.schema";
|
||||
import { PasswordInput } from "@/components/wrappers/auth/PaswordInput/password-input";
|
||||
import {signUp} from "@/lib/auth/auth-client";
|
||||
|
||||
export type registerFormProps = {
|
||||
defaultValues?: RegisterType;
|
||||
};
|
||||
|
||||
export const RegisterForm = (props: registerFormProps) => {
|
||||
|
||||
const form = useZodForm({
|
||||
schema: RegisterSchema,
|
||||
});
|
||||
const router = useRouter();
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (values: RegisterType) => {
|
||||
console.log(values);
|
||||
const createUser = await registerUserAction(values);
|
||||
console.log(createUser);
|
||||
const data = createUser?.data?.data;
|
||||
if (createUser?.serverError || !data) {
|
||||
console.log(createUser?.serverError);
|
||||
toast.error(createUser?.serverError);
|
||||
return;
|
||||
}
|
||||
toast.success(`Success`);
|
||||
router.push(`/login`);
|
||||
router.refresh();
|
||||
await signUp.email(values, {
|
||||
onSuccess: () => {
|
||||
toast.success(`Success`);
|
||||
router.push(`/login`);
|
||||
router.refresh();
|
||||
},
|
||||
onError: (error) => {
|
||||
console.log(error);
|
||||
toast.error(error.error.message);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Card>
|
||||
Reference in New Issue
Block a user