next-auth-mfelfelani72 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ export interface LoginMetadataInterface {
2
+ title?: string;
3
+ description?: string;
4
+ logoUrl?: string;
5
+ }
6
+ export interface LangInterface {
7
+ params: {
8
+ lang?: string;
9
+ } | Promise<{
10
+ lang?: string;
11
+ }>;
12
+ }
13
+ export interface ClientLoginInterface {
14
+ onSubmit: (formData: FormData) => void;
15
+ errors?: {
16
+ username?: string;
17
+ password?: string;
18
+ };
19
+ message?: string | null;
20
+ }
21
+ export interface LoginInterface {
22
+ loginRoute: string;
23
+ metadata?: LoginMetadataInterface;
24
+ onGoogleLogin?: () => void;
25
+ dict: any;
26
+ lang: string;
27
+ UiComponent?: React.ComponentType<ClientLoginInterface>;
28
+ }
29
+ export interface RegisterInterface {
30
+ registerRoute: string;
31
+ onGoogleRegister?: () => void;
32
+ dict?: any;
33
+ lang?: string;
34
+ }
35
+ export interface ClientRegisterInterface {
36
+ onSubmit: (formData: FormData) => void;
37
+ errors: {
38
+ name?: string;
39
+ email?: string;
40
+ password?: string;
41
+ confirmPassword?: string;
42
+ };
43
+ message: string | null;
44
+ loading?: boolean;
45
+ dict?: any;
46
+ lang?: string;
47
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 07:56:22
6
+ * @Description:
7
+ */
8
+ export {};
@@ -1,14 +1,5 @@
1
1
  import React from "react";
2
- import type { LoginProps } from "../types";
3
- interface LoginComponentProps {
4
- onSubmit: (formData: FormData) => void;
5
- errors?: {
6
- username?: string;
7
- password?: string;
8
- };
9
- message?: string | null;
10
- }
11
- export default function Login({ loginRoute, onGoogleLogin, UiComponent, }: LoginProps & {
12
- UiComponent?: React.ComponentType<LoginComponentProps>;
2
+ import type { LoginInterface, ClientLoginInterface } from "../Interfaces";
3
+ export default function Login({ loginRoute, onGoogleLogin, UiComponent, dict, lang, }: LoginInterface & {
4
+ UiComponent?: React.ComponentType<ClientLoginInterface>;
13
5
  }): import("react/jsx-runtime").JSX.Element;
14
- export {};
@@ -1,15 +1,21 @@
1
+ /*
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 08:02:55
6
+ * @Description:
7
+ */
1
8
  "use client";
2
9
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
10
  import { useState } from "react";
4
11
  // Components
5
12
  import UiLogin from "./demo/UiLogin";
6
- export default function Login({ loginRoute, onGoogleLogin, UiComponent, // ⬅️ اضافه شد
7
- }) {
8
- // states
13
+ export default function Login({ loginRoute, onGoogleLogin, UiComponent, dict, lang, }) {
14
+ // States
9
15
  const [errors, setErrors] = useState({});
10
16
  const [message, setMessage] = useState(null);
11
17
  const [loading, setLoading] = useState(false);
12
- // functions
18
+ // Functions
13
19
  const handleSubmit = async (formData) => {
14
20
  setMessage(null);
15
21
  setErrors({});
@@ -34,7 +40,7 @@ export default function Login({ loginRoute, onGoogleLogin, UiComponent, // ⬅
34
40
  const res = await fetch(loginRoute, {
35
41
  method: "POST",
36
42
  headers: { "Content-Type": "application/json" },
37
- body: JSON.stringify({ username, password }),
43
+ body: JSON.stringify({ email: username, password }),
38
44
  });
39
45
  const data = await res.json();
40
46
  if (!res.ok) {
@@ -50,7 +56,6 @@ export default function Login({ loginRoute, onGoogleLogin, UiComponent, // ⬅
50
56
  setLoading(false);
51
57
  }
52
58
  };
53
- // ✅ اگر UiComponent پاس داده شده باشه، اون استفاده میشه
54
59
  const RenderUi = UiComponent || UiLogin;
55
60
  return (_jsxs(_Fragment, { children: [_jsx(RenderUi, { onSubmit: handleSubmit, errors: errors, message: message }), loading && (_jsx("p", { className: "text-center text-gray-200 mt-2", children: "Logging in..." })), onGoogleLogin && (_jsx("div", { className: "flex justify-center mt-4", children: _jsx("button", { onClick: onGoogleLogin, className: "px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition", children: "Sign in with Google" }) }))] }));
56
61
  }
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ import type { RegisterInterface, ClientRegisterInterface } from "../Interfaces";
3
+ export default function Register({ registerRoute, onGoogleRegister, UiComponent, dict, lang, }: RegisterInterface & {
4
+ UiComponent?: React.ComponentType<ClientRegisterInterface>;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,76 @@
1
+ /*
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 06:57:46
6
+ * @Description:
7
+ */
8
+ "use client";
9
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
10
+ import { useState } from "react";
11
+ // Components
12
+ import UiRegister from "./demo/UiRegister";
13
+ export default function Register({ registerRoute, onGoogleRegister, UiComponent, dict, lang, }) {
14
+ // States
15
+ const [errors, setErrors] = useState({});
16
+ const [message, setMessage] = useState(null);
17
+ const [loading, setLoading] = useState(false);
18
+ // Functions
19
+ const handleSubmit = async (formData) => {
20
+ setMessage(null);
21
+ setErrors({});
22
+ const name = formData.get("name") || "";
23
+ const email = formData.get("email") || "";
24
+ const password = formData.get("password") || "";
25
+ const confirmPassword = formData.get("confirmPassword") || "";
26
+ const newErrors = {};
27
+ if (!name.trim())
28
+ newErrors.name = "Name is required";
29
+ else if (name.length < 2)
30
+ newErrors.name = "Name must be at least 2 characters";
31
+ if (!email.trim())
32
+ newErrors.email = "Email is required";
33
+ else if (!/\S+@\S+\.\S+/.test(email))
34
+ newErrors.email = "Email is invalid";
35
+ if (!password)
36
+ newErrors.password = "Password is required";
37
+ else if (password.length < 6)
38
+ newErrors.password = "Password must be at least 6 characters";
39
+ if (!confirmPassword)
40
+ newErrors.confirmPassword = "Please confirm your password";
41
+ else if (password !== confirmPassword)
42
+ newErrors.confirmPassword = "Passwords do not match";
43
+ if (Object.keys(newErrors).length > 0) {
44
+ setErrors(newErrors);
45
+ setMessage("Please fix the errors below.");
46
+ return;
47
+ }
48
+ setLoading(true);
49
+ try {
50
+ const res = await fetch(registerRoute, {
51
+ method: "POST",
52
+ headers: { "Content-Type": "application/json" },
53
+ body: JSON.stringify({
54
+ name,
55
+ email,
56
+ password,
57
+ password_confirmation: confirmPassword,
58
+ }),
59
+ });
60
+ const data = await res.json();
61
+ if (!res.ok) {
62
+ setMessage((data === null || data === void 0 ? void 0 : data.message) || "Registration failed");
63
+ return;
64
+ }
65
+ setMessage((data === null || data === void 0 ? void 0 : data.message) || "Registration successful");
66
+ }
67
+ catch (err) {
68
+ setMessage((err === null || err === void 0 ? void 0 : err.message) || "Network error");
69
+ }
70
+ finally {
71
+ setLoading(false);
72
+ }
73
+ };
74
+ const RenderUi = UiComponent || UiRegister;
75
+ return (_jsxs(_Fragment, { children: [_jsx(RenderUi, { onSubmit: handleSubmit, errors: errors, message: message, dict: dict, lang: lang }), loading && (_jsx("p", { className: "text-center text-gray-200 mt-2", children: "Registering..." })), onGoogleRegister && (_jsx("div", { className: "flex justify-center mt-4", children: _jsx("button", { onClick: onGoogleRegister, className: "px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition", children: "Sign up with Google" }) }))] }));
76
+ }
@@ -1,10 +1,2 @@
1
- interface ClientLoginProps {
2
- onSubmit: (formData: FormData) => void;
3
- errors?: {
4
- username?: string;
5
- password?: string;
6
- };
7
- message?: string | null;
8
- }
9
- export default function UiLogin({ onSubmit, errors, message, }: ClientLoginProps): import("react/jsx-runtime").JSX.Element;
10
- export {};
1
+ import { ClientLoginInterface } from "@/Interfaces";
2
+ export default function UiLogin({ onSubmit, errors, message, }: ClientLoginInterface): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,26 @@
1
+ /*
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 08:04:22
6
+ * @Description:
7
+ */
1
8
  "use client";
2
9
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ import { useState, useEffect } from "react";
3
11
  import Image from "next/image";
12
+ import Link from "next/link";
4
13
  export default function UiLogin({ onSubmit, errors, message, }) {
5
- return (_jsx("div", { className: "fixed inset-0 overflow-hidden flex items-center justify-center bg-gradient-to-br from-purple-900 via-purple-800 to-black p-4", children: _jsxs("div", { className: "w-full max-w-md bg-white/20 backdrop-blur-md rounded-2xl shadow-xl p-8 border border-white/30", children: [_jsx("div", { className: "flex justify-center mb-6", children: _jsx(Image, { src: "/logo.png", alt: "Logo", width: 80, height: 80, className: "rounded-full shadow" }) }), _jsx("h1", { className: "text-2xl font-bold text-center text-white mb-2", children: "Welcome Back" }), _jsx("p", { className: "text-center text-gray-200 mb-6 text-sm", children: "Login with your credentials to continue" }), message && (_jsx("div", { role: "alert", className: "mb-4 text-center text-red-300 font-medium", children: message })), _jsxs("form", { onSubmit: (e) => {
14
+ // States
15
+ const [visible, setVisible] = useState(false);
16
+ // Functions
17
+ useEffect(() => {
18
+ setVisible(true);
19
+ }, []);
20
+ return (_jsx("div", { className: "fixed inset-0 overflow-hidden flex items-center justify-center bg-gradient-to-br from-purple-900 via-purple-800 to-black p-4", children: _jsxs("div", { className: `w-full max-w-md bg-white/20 backdrop-blur-md rounded-2xl shadow-xl p-8 border border-white/30
21
+ transform transition-all duration-700 ease-out
22
+ ${visible ? "opacity-100 scale-100" : "opacity-0 scale-95"}
23
+ `, children: [_jsx("div", { className: "flex justify-center mb-6", children: _jsx(Image, { src: "/logo.png", alt: "Logo", width: 80, height: 80, className: "rounded-full shadow" }) }), _jsx("h1", { className: "text-2xl font-bold text-center text-white mb-2", children: "Welcome Back" }), _jsx("p", { className: "text-center text-gray-200 mb-6 text-sm", children: "Login with your credentials to continue" }), message && (_jsx("div", { role: "alert", className: "mb-4 text-center text-red-300 font-medium", children: message })), _jsxs("form", { onSubmit: (e) => {
6
24
  e.preventDefault();
7
25
  const formData = new FormData(e.currentTarget);
8
26
  onSubmit(formData);
@@ -10,5 +28,5 @@ export default function UiLogin({ onSubmit, errors, message, }) {
10
28
  ? "border-red-500"
11
29
  : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.username) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.username }))] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "password", className: "block text-sm font-medium text-white mb-1", children: "Password" }), _jsx("input", { id: "password", name: "password", type: "password", placeholder: "Enter your password", required: true, className: `w-full px-4 py-2 rounded-lg bg-white/20 focus:bg-white/30 border focus:outline-none focus:ring-2 text-white placeholder-gray-200 ${(errors === null || errors === void 0 ? void 0 : errors.password)
12
30
  ? "border-red-500"
13
- : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.password) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.password }))] }), _jsx("button", { type: "submit", className: "w-full py-2 bg-purple-700/80 text-white rounded-lg hover:bg-purple-800 transition", children: "Log In" }), _jsxs("div", { className: "flex justify-center gap-4 mt-4", children: [_jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-red-500 hover:bg-red-600 text-white transition font-bold text-lg", children: "G" }), _jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-blue-600 hover:bg-blue-700 text-white transition font-bold text-lg", children: "F" }), _jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-blue-400 hover:bg-blue-500 text-white transition font-bold text-lg", children: "T" })] }), _jsxs("p", { className: "text-center text-sm text-gray-200 mt-4", children: ["Don\u2019t have an account?", " ", _jsx("a", { href: "#", className: "underline hover:text-white", children: "Sign up" })] })] })] }) }));
31
+ : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.password) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.password }))] }), _jsx("button", { type: "submit", className: "w-full py-2 bg-purple-700/80 text-white rounded-lg hover:bg-purple-800 transition", children: "Log In" }), _jsxs("div", { className: "flex justify-center gap-4 mt-4", children: [_jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-red-500 hover:bg-red-600 text-white transition font-bold text-lg", children: "G" }), _jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-blue-600 hover:bg-blue-700 text-white transition font-bold text-lg", children: "F" }), _jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-blue-400 hover:bg-blue-500 text-white transition font-bold text-lg", children: "T" })] }), _jsxs("p", { className: "text-center text-sm text-gray-200 mt-4", children: ["Don\u2019t have an account?", " ", _jsx(Link, { href: "/en/register", className: "underline hover:text-white", scroll: false, children: "Register" })] })] })] }) }));
14
32
  }
@@ -0,0 +1,2 @@
1
+ import { ClientRegisterInterface } from "@/Interfaces";
2
+ export default function UiRegister({ onSubmit, errors, message, dict, lang, }: ClientRegisterInterface): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,36 @@
1
+ /*
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 08:04:22
6
+ * @Description:
7
+ */
8
+ "use client";
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ import { useState, useEffect } from "react";
11
+ import Image from "next/image";
12
+ import Link from "next/link";
13
+ export default function UiRegister({ onSubmit, errors, message, dict, lang, }) {
14
+ // States
15
+ const [visible, setVisible] = useState(false);
16
+ // Functions
17
+ useEffect(() => {
18
+ setVisible(true);
19
+ }, []);
20
+ return (_jsx("div", { className: "fixed inset-0 overflow-hidden flex items-center justify-center bg-gradient-to-br from-purple-900 via-purple-800 to-black p-4", children: _jsxs("div", { className: `w-full max-w-md bg-white/20 backdrop-blur-md rounded-2xl shadow-xl p-8 border border-white/30
21
+ transform transition-all duration-700 ease-out
22
+ ${visible ? "opacity-100 scale-100" : "opacity-0 scale-95"}
23
+ `, children: [_jsx("div", { className: "flex justify-center mb-6", children: _jsx(Image, { src: "/logo.png", alt: "Logo", width: 80, height: 80, className: "rounded-full shadow" }) }), _jsx("h1", { className: "text-2xl font-bold text-center text-white mb-2", children: "Create Account" }), _jsx("p", { className: "text-center text-gray-200 mb-6 text-sm", children: "Sign up to get started" }), message && (_jsx("div", { role: "alert", className: "mb-4 text-center text-red-300 font-medium", children: message })), _jsxs("form", { onSubmit: (e) => {
24
+ e.preventDefault();
25
+ const formData = new FormData(e.currentTarget);
26
+ onSubmit(formData);
27
+ }, noValidate: true, className: "space-y-5", children: [_jsxs("div", { children: [_jsx("label", { htmlFor: "name", className: "block text-sm font-medium text-white mb-1", children: "Full Name" }), _jsx("input", { id: "name", name: "name", type: "text", placeholder: "Enter your full name", required: true, className: `w-full px-4 py-2 rounded-lg bg-white/20 focus:bg-white/30 border focus:outline-none focus:ring-2 text-white placeholder-gray-200 ${(errors === null || errors === void 0 ? void 0 : errors.name)
28
+ ? "border-red-500"
29
+ : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.name) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.name }))] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "email", className: "block text-sm font-medium text-white mb-1", children: "Email" }), _jsx("input", { id: "email", name: "email", type: "email", placeholder: "Enter your email", required: true, className: `w-full px-4 py-2 rounded-lg bg-white/20 focus:bg-white/30 border focus:outline-none focus:ring-2 text-white placeholder-gray-200 ${(errors === null || errors === void 0 ? void 0 : errors.email)
30
+ ? "border-red-500"
31
+ : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.email) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.email }))] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "password", className: "block text-sm font-medium text-white mb-1", children: "Password" }), _jsx("input", { id: "password", name: "password", type: "password", placeholder: "Enter your password", required: true, className: `w-full px-4 py-2 rounded-lg bg-white/20 focus:bg-white/30 border focus:outline-none focus:ring-2 text-white placeholder-gray-200 ${(errors === null || errors === void 0 ? void 0 : errors.password)
32
+ ? "border-red-500"
33
+ : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.password) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.password }))] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "confirmPassword", className: "block text-sm font-medium text-white mb-1", children: "Confirm Password" }), _jsx("input", { id: "confirmPassword", name: "confirmPassword", type: "password", placeholder: "Confirm your password", required: true, className: `w-full px-4 py-2 rounded-lg bg-white/20 focus:bg-white/30 border focus:outline-none focus:ring-2 text-white placeholder-gray-200 ${(errors === null || errors === void 0 ? void 0 : errors.confirmPassword)
34
+ ? "border-red-500"
35
+ : "border-gray-300 focus:ring-purple-400"}` }), (errors === null || errors === void 0 ? void 0 : errors.confirmPassword) && (_jsx("p", { className: "mt-1 text-sm text-red-300", children: errors.confirmPassword }))] }), _jsx("button", { type: "submit", className: "w-full py-2 bg-purple-700/80 text-white rounded-lg hover:bg-purple-800 transition", children: "Sign Up" }), _jsxs("div", { className: "flex justify-center gap-4 mt-4", children: [_jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-red-500 hover:bg-red-600 text-white transition font-bold text-lg", children: "G" }), _jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-blue-600 hover:bg-blue-700 text-white transition font-bold text-lg", children: "F" }), _jsx("button", { type: "button", className: "flex items-center justify-center w-10 h-10 rounded-full bg-blue-400 hover:bg-blue-500 text-white transition font-bold text-lg", children: "T" })] }), _jsxs("p", { className: "text-center text-sm text-gray-200 mt-4", children: ["Already have an account?", " ", _jsx(Link, { href: `/${lang}/login`, className: "underline hover:text-white", scroll: false, children: "Login" })] })] })] }) }));
36
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,11 @@
1
+ /**
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 10:49:19
6
+ * @Description:
7
+ */
1
8
  export { default as Login } from "./components/Login";
2
- export { loginHandler } from "./lib/loginHandler";
9
+ export { default as Rgister } from "./components/Register";
10
+ export { loginHandler } from "./libs/loginHandler";
11
+ export { registerHandler } from "./libs/registerHandler";
package/dist/index.js CHANGED
@@ -1,4 +1,13 @@
1
+ /**
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 10:49:19
6
+ * @Description:
7
+ */
1
8
  // Components
2
9
  export { default as Login } from "./components/Login";
10
+ export { default as Rgister } from "./components/Register";
3
11
  // Server handlers
4
- export { loginHandler } from "./lib/loginHandler";
12
+ export { loginHandler } from "./libs/loginHandler";
13
+ export { registerHandler } from "./libs/registerHandler";
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 10:50:06
6
+ * @Description:
7
+ */
1
8
  import { NextRequest, NextResponse } from "next/server";
2
9
  export declare function loginHandler(apiUrl: string): (req: NextRequest) => Promise<NextResponse<{
3
10
  message: any;
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 10:50:06
6
+ * @Description:
7
+ */
1
8
  import { NextResponse } from "next/server";
2
9
  import cookie from "cookie";
3
10
  export function loginHandler(apiUrl) {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 10:50:57
6
+ * @Description:
7
+ */
8
+ import { NextRequest, NextResponse } from "next/server";
9
+ export declare function registerHandler(apiUrl: string): (req: NextRequest) => Promise<NextResponse<{
10
+ message: any;
11
+ }>>;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-02 10:50:57
6
+ * @Description:
7
+ */
8
+ import { NextResponse } from "next/server";
9
+ import cookie from "cookie";
10
+ export function registerHandler(apiUrl) {
11
+ return async function POST(req) {
12
+ try {
13
+ const body = await req.json();
14
+ if (!body.name ||
15
+ !body.email ||
16
+ !body.password ||
17
+ !body.password_confirmation) {
18
+ return NextResponse.json({ message: "All fields are required" }, { status: 400 });
19
+ }
20
+ if (body.password !== body.password_confirmation) {
21
+ return NextResponse.json({ message: "Passwords do not match" }, { status: 400 });
22
+ }
23
+ const response = await fetch(`${process.env.API_URL}/register`, {
24
+ method: "POST",
25
+ headers: { "Content-Type": "application/json" },
26
+ body: JSON.stringify(body),
27
+ });
28
+ const data = await response.json();
29
+ if (response.ok && data.accessToken) {
30
+ const headers = new Headers();
31
+ headers.append("Set-Cookie", cookie.serialize("accessToken", data.accessToken, {
32
+ httpOnly: true,
33
+ secure: process.env.NODE_ENV === "production",
34
+ sameSite: "strict",
35
+ path: "/",
36
+ maxAge: 60 * 15,
37
+ }));
38
+ return NextResponse.json({
39
+ message: "Registration successful",
40
+ user: data.user,
41
+ }, { headers });
42
+ }
43
+ return NextResponse.json({ message: data.message || "Registration failed" }, { status: response.status });
44
+ }
45
+ catch (err) {
46
+ return NextResponse.json({ message: err.message || "Internal server error" }, { status: 500 });
47
+ }
48
+ };
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-auth-mfelfelani72",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/dist/types.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export interface LoginMetadata {
2
- title?: string;
3
- description?: string;
4
- logoUrl?: string;
5
- }
6
- export interface LoginProps {
7
- loginRoute: string;
8
- metadata?: LoginMetadata;
9
- onGoogleLogin?: () => void;
10
- }
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};