Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack -p 3001",
"dev": "next dev --turbopack -p 3000",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down Expand Up @@ -34,6 +34,7 @@
"@mui/x-data-grid": "^8.14.1",
"@mui/x-date-pickers": "^8.14.1",
"axios": "^1.12.2",
"better-auth": "^1.3.34",
"clsx": "^2.1.1",
"dayjs": "^1.11.18",
"gsap": "^3.13.0",
Expand Down
22 changes: 12 additions & 10 deletions apps/client/src/app/authentication/default/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use client';

import { signIn } from 'next-auth/react';
import LoginForm from 'components/sections/authentications/default/LoginForm';
import paths from 'routes/paths';
import { defaultJwtAuthCredentials } from 'config';
import paths, { rootPaths } from 'routes/paths';
import { authClient } from 'lib/auth-client';
import { useRouter } from 'next/navigation';

const Page = () => {
const handleLogin = async (data: { email: string; password: string }) => {
return await signIn('credentials', {
email: data.email,
password: data.password,
redirect: false,
});
const router = useRouter()
const handleLogin = async (data: { email: string; password: string , rememberDevice: boolean }) => {
try {
const response = await authClient.signIn.email(data)
return response

} catch (error) {
return error
}
};

return (
Expand All @@ -21,7 +24,6 @@ const Page = () => {
forgotPasswordLink={paths.forgotPassword}
socialAuth={false}
rememberDevice={true}
defaultCredential={defaultJwtAuthCredentials}
/>
);
};
Expand Down
20 changes: 13 additions & 7 deletions apps/client/src/app/authentication/default/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
'use client';

import { signIn } from 'next-auth/react';
import { authClient } from 'lib/auth-client';
import SignupForm from 'components/sections/authentications/default/SignupForm';

const Page = () => {
const handleSignup = async (data: { name: string; email: string; password: string }) => {
return await signIn('signup', {
name: data.name,
email: data.email,
password: data.password,
redirect: false,
});

try {
const response = await authClient.signUp.email({
name: data.name,
email: data.email,
password: data.password,
});
return response;
} catch (error) {
console.error(error);
return error;
}
};

return <SignupForm handleSignup={handleSignup} socialAuth={false} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import DefaultCredentialAlert from '../common/DefaultCredentialAlert';
import SocialAuth from './SocialAuth';

interface LoginFormProps {
handleLogin: (data: LoginFormValues) => Promise<SignInResponse | undefined>;
handleLogin: (data: LoginFormValues) => Promise<any | undefined>;
signUpLink: string;
socialAuth?: boolean;
forgotPasswordLink?: string;
Expand All @@ -34,6 +34,7 @@ interface LoginFormProps {
export interface LoginFormValues {
email: string;
password: string;
rememberDevice: boolean;
}

const schema = yup
Expand All @@ -43,6 +44,7 @@ const schema = yup
.email('Please provide a valid email address.')
.required('This field is required'),
password: yup.string().required('This field is required'),
rememberDevice: yup.boolean().optional().default(false),
})
.required();

Expand Down Expand Up @@ -70,7 +72,7 @@ const LoginForm = ({

const onSubmit = async (data: LoginFormValues) => {
const res = await handleLogin(data);
if (res?.ok) {
if (res?.data?.token) {
router.refresh();
router.push(callbackUrl ? callbackUrl : rootPaths.root);
}
Expand Down Expand Up @@ -193,8 +195,8 @@ const LoginForm = ({
}}
>
{rememberDevice && (
<FormControlLabel
control={<Checkbox name="checked" color="primary" size="small" />}
<FormControlLabel {...register('rememberDevice')}
control={<Checkbox id='rememberDevice' name="rememberDevice" color="primary" size="small" />}
label={
<Typography
variant="subtitle2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import {
import Grid from "@mui/material/Grid";
import IconifyIcon from "components/base/IconifyIcon";
import PasswordTextField from "components/common/PasswordTextField";
import { SignInResponse } from "next-auth/react";
import { useForm } from "react-hook-form";
import paths from "routes/paths";
import * as yup from "yup";
import SocialAuth from "./SocialAuth";

interface SignupFormProps {
handleSignup: (data: SignupFormValues) => Promise<SignInResponse | undefined>;
handleSignup: (data: SignupFormValues) => Promise<any | undefined>;
socialAuth?: boolean;
}

Expand Down
7 changes: 7 additions & 0 deletions apps/client/src/lib/auth-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createAuthClient } from "better-auth/react"

export const authClient = createAuthClient({
/** The base URL of the server (optional if you're using the same domain) */
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:4000/api/auth",
fetchOptions: { credentials: 'include' },
})
2 changes: 2 additions & 0 deletions apps/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ STRIPE_SECRET_KEY=sk_test_

GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
TRUSTED_ORIGINS=http://localhost:3000


1 change: 1 addition & 0 deletions apps/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const auth: AuthInstance = betterAuth({
transaction: true,
debugLogs: true,
}),
trustedOrigins: ['http://localhost:3000'],
// npx @better-auth/cli@latest generate
appName: 'Server',
plugins: [
Expand Down
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"nest": "nest",
"dev": "pnpm run start:dev",
"prisma:generate": "pnpx prisma generate",
"prisma:dev": "pnpx prisma migrate dev",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
Expand Down
15 changes: 13 additions & 2 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async function bootstrap() {
"'self'",
'https://cdn.jsdelivr.net',
'http://localhost:3000',
'http://localhost:4000',
],
},
},
Expand All @@ -45,7 +46,17 @@ async function bootstrap() {
origin: corsConfig.origins,
credentials: corsConfig.credentials,
methods: corsConfig.methods,
allowedHeaders: corsConfig.allowedHeaders,
// allowedHeaders: corsConfig.allowedHeaders,
allowedHeaders:
corsConfig.allowedHeaders.length > 0
? corsConfig.allowedHeaders
: [
'Content-Type',
'Authorization',
'X-Requested-With',
'Accept',
'Origin',
],
});
app.useGlobalPipes(
new ValidationPipe({
Expand All @@ -72,7 +83,7 @@ async function bootstrap() {
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, documentFactory);

// app.setGlobalPrefix('api');
app.setGlobalPrefix('api');
await app.listen(port);
Logger.debug(`Server started on http://localhost:${port}`);
Logger.debug(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev:client": "pnpm --filter client dev",
"prebuild": "pnpm -r --filter server run prisma:generate",
"dev:server": "pnpm --filter server start:dev",
"build:client": "pnpm --filter client build",
"build:client": "pnpm --filter client build",
"prisma:dev": "pnpm --filter server run prisma:dev",
"build:server": "pnpm --filter server build",
"start:client": "pnpm --filter client start",
"start:server": "pnpm --filter server start",
Expand Down
15 changes: 11 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.