Run prettier
This commit is contained in:
parent
e6806aaa54
commit
24cb81bce0
21 changed files with 4203 additions and 3520 deletions
|
|
@ -1,10 +1,10 @@
|
|||
"use server";
|
||||
'use server';
|
||||
|
||||
import { z } from "zod";
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createUser, getUser } from "@/db/queries";
|
||||
import { createUser, getUser } from '@/db/queries';
|
||||
|
||||
import { signIn } from "./auth";
|
||||
import { signIn } from './auth';
|
||||
|
||||
const authFormSchema = z.object({
|
||||
email: z.string().email(),
|
||||
|
|
@ -12,74 +12,74 @@ const authFormSchema = z.object({
|
|||
});
|
||||
|
||||
export interface LoginActionState {
|
||||
status: "idle" | "in_progress" | "success" | "failed" | "invalid_data";
|
||||
status: 'idle' | 'in_progress' | 'success' | 'failed' | 'invalid_data';
|
||||
}
|
||||
|
||||
export const login = async (
|
||||
_: LoginActionState,
|
||||
formData: FormData,
|
||||
formData: FormData
|
||||
): Promise<LoginActionState> => {
|
||||
try {
|
||||
const validatedData = authFormSchema.parse({
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
email: formData.get('email'),
|
||||
password: formData.get('password'),
|
||||
});
|
||||
|
||||
await signIn("credentials", {
|
||||
await signIn('credentials', {
|
||||
email: validatedData.email,
|
||||
password: validatedData.password,
|
||||
redirect: false,
|
||||
});
|
||||
|
||||
return { status: "success" };
|
||||
return { status: 'success' };
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return { status: "invalid_data" };
|
||||
return { status: 'invalid_data' };
|
||||
}
|
||||
|
||||
return { status: "failed" };
|
||||
return { status: 'failed' };
|
||||
}
|
||||
};
|
||||
|
||||
export interface RegisterActionState {
|
||||
status:
|
||||
| "idle"
|
||||
| "in_progress"
|
||||
| "success"
|
||||
| "failed"
|
||||
| "user_exists"
|
||||
| "invalid_data";
|
||||
| 'idle'
|
||||
| 'in_progress'
|
||||
| 'success'
|
||||
| 'failed'
|
||||
| 'user_exists'
|
||||
| 'invalid_data';
|
||||
}
|
||||
|
||||
export const register = async (
|
||||
_: RegisterActionState,
|
||||
formData: FormData,
|
||||
formData: FormData
|
||||
): Promise<RegisterActionState> => {
|
||||
try {
|
||||
const validatedData = authFormSchema.parse({
|
||||
email: formData.get("email"),
|
||||
password: formData.get("password"),
|
||||
email: formData.get('email'),
|
||||
password: formData.get('password'),
|
||||
});
|
||||
|
||||
let [user] = await getUser(validatedData.email);
|
||||
|
||||
if (user) {
|
||||
return { status: "user_exists" } as RegisterActionState;
|
||||
return { status: 'user_exists' } as RegisterActionState;
|
||||
} else {
|
||||
await createUser(validatedData.email, validatedData.password);
|
||||
await signIn("credentials", {
|
||||
await signIn('credentials', {
|
||||
email: validatedData.email,
|
||||
password: validatedData.password,
|
||||
redirect: false,
|
||||
});
|
||||
|
||||
return { status: "success" };
|
||||
return { status: 'success' };
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
return { status: "invalid_data" };
|
||||
return { status: 'invalid_data' };
|
||||
}
|
||||
|
||||
return { status: "failed" };
|
||||
return { status: 'failed' };
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { compare } from "bcrypt-ts";
|
||||
import NextAuth, { User, Session } from "next-auth";
|
||||
import Credentials from "next-auth/providers/credentials";
|
||||
import { compare } from 'bcrypt-ts';
|
||||
import NextAuth, { User, Session } from 'next-auth';
|
||||
import Credentials from 'next-auth/providers/credentials';
|
||||
|
||||
import { getUser } from "@/db/queries";
|
||||
import { getUser } from '@/db/queries';
|
||||
|
||||
import { authConfig } from "./auth.config";
|
||||
import { authConfig } from './auth.config';
|
||||
|
||||
interface ExtendedSession extends Session {
|
||||
user: User;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue