next-auth-mfelfelani72 0.0.45 → 0.0.47

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.
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import type { LoginProps } from "../../../types";
3
- export default function Login({ layout, theme, className, translations, }: LoginProps): React.JSX.Element;
3
+ export default function Login({ layout, theme, className, overlayOpacity, translations, }: LoginProps): React.JSX.Element;
@@ -6,8 +6,9 @@
6
6
  * @Description:
7
7
  */
8
8
  "use client";
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
- import { useState, useMemo, lazy } from "react";
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ import { useState, useMemo, lazy, } from "react";
11
+ import { useRouter } from "next/navigation";
11
12
  // Components
12
13
  const LazyTwoColumn = lazy(() => import("../../../components/demo/auth/layouts/twoColumn/LoginLanding"));
13
14
  // Constants
@@ -17,7 +18,8 @@ const LAYOUT_MAP = {
17
18
  // Functions
18
19
  import { cn } from "forma-li";
19
20
  import { setTranslationOverrides } from "../../../locale";
20
- export default function Login({ layout, theme, className, translations, }) {
21
+ export default function Login({ layout, theme, className, overlayOpacity = 0, translations, }) {
22
+ const router = useRouter();
21
23
  setTranslationOverrides(translations);
22
24
  const [errors, setErrors] = useState({});
23
25
  const [message, setMessage] = useState(null);
@@ -27,14 +29,18 @@ export default function Login({ layout, theme, className, translations, }) {
27
29
  const email = formData.get("email") || "";
28
30
  const password = formData.get("password") || "";
29
31
  const newErrors = {};
30
- if (!email.trim())
32
+ if (!email.trim()) {
31
33
  newErrors.email = "Email is required";
32
- else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
34
+ }
35
+ else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
33
36
  newErrors.email = "Invalid email format";
34
- if (!password)
37
+ }
38
+ if (!password) {
35
39
  newErrors.password = "Password is required";
36
- else if (password.length < 6)
40
+ }
41
+ else if (password.length < 6) {
37
42
  newErrors.password = "Password must be at least 6 characters";
43
+ }
38
44
  if (Object.keys(newErrors).length > 0) {
39
45
  setErrors(newErrors);
40
46
  setMessage("Please fix the errors below.");
@@ -43,15 +49,22 @@ export default function Login({ layout, theme, className, translations, }) {
43
49
  try {
44
50
  const res = await fetch("/api/auth/login", {
45
51
  method: "POST",
46
- headers: { "Content-Type": "application/json" },
47
- body: JSON.stringify({ email, password }),
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ },
55
+ body: JSON.stringify({
56
+ email,
57
+ password,
58
+ }),
48
59
  });
49
60
  const data = await res.json();
61
+ console.log("LOGIN RESPONSE:", data);
50
62
  if (!res.ok) {
51
63
  setMessage((data === null || data === void 0 ? void 0 : data.message) || "Login failed");
52
64
  return;
53
65
  }
54
- setMessage((data === null || data === void 0 ? void 0 : data.message) || "Login successful");
66
+ const redirectTo = (data === null || data === void 0 ? void 0 : data.redirectTo) || "/";
67
+ router.push(redirectTo);
55
68
  }
56
69
  catch (err) {
57
70
  setMessage((err === null || err === void 0 ? void 0 : err.message) || "Network error");
@@ -60,7 +73,9 @@ export default function Login({ layout, theme, className, translations, }) {
60
73
  const RenderUi = useMemo(() => {
61
74
  return LAYOUT_MAP[layout || ""] || LAYOUT_MAP.twoColumn;
62
75
  }, [layout]);
63
- return (_jsx("div", { style: {
76
+ return (_jsxs("div", { className: cn("relative z-10 w-full max-w-md px-4 max-h-screen bg-cover bg-center bg-fixed overflow-hidden", className), style: {
64
77
  backgroundImage: `url('/images/jpg/${theme || "default"}_auth.jpeg')`,
65
- }, className: cn("zz-10 w-full max-w-md px-4 max-h-screen bg-cover bg-center bg-fixed overflow-hidden", className), children: _jsx(RenderUi, { onSubmit: handleSubmit, errors: errors, message: message, theme: theme, translations: translations }) }));
78
+ }, children: [_jsx("div", { className: "absolute inset-0 bg-black pointer-events-none", style: {
79
+ opacity: overlayOpacity,
80
+ } }), _jsx("div", { className: "relative z-10", children: _jsx(RenderUi, { onSubmit: handleSubmit, errors: errors, message: message, theme: theme, translations: translations }) })] }));
66
81
  }
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import type { RegisterProps } from "../../../types";
3
- export default function Register({ layout, theme, className, }: RegisterProps): React.JSX.Element;
3
+ export default function Register({ layout, theme, className, overlayOpacity, translations, }: RegisterProps): React.JSX.Element;
@@ -1,12 +1,23 @@
1
+ /*
2
+ * @Author: Mohammad Felfelani
3
+ * @Email: mfelfelani72@gmail.com
4
+ * @Team:
5
+ * @Date: 2025-10-04 11:48:20
6
+ * @Description:
7
+ */
1
8
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
10
  import { useState, useMemo, lazy } from "react";
11
+ // Functions
4
12
  import { cn } from "forma-li";
13
+ import { setTranslationOverrides } from "../../../locale";
14
+ // Constants
5
15
  const LazyTwoColumn = lazy(() => import("../../../components/demo/auth/layouts/twoColumn/RegisterLanding"));
6
16
  const LAYOUT_MAP = {
7
17
  twoColumn: LazyTwoColumn,
8
18
  };
9
- export default function Register({ layout = "twoColumn", theme, className, }) {
19
+ export default function Register({ layout = "twoColumn", theme, className, overlayOpacity = 0, translations, }) {
20
+ setTranslationOverrides(translations);
10
21
  const [errors, setErrors] = useState({});
11
22
  const [message, setMessage] = useState(null);
12
23
  const validate = (formData) => {
@@ -67,7 +78,9 @@ export default function Register({ layout = "twoColumn", theme, className, }) {
67
78
  const RenderUi = useMemo(() => {
68
79
  return LAYOUT_MAP[layout] || LAYOUT_MAP.twoColumn;
69
80
  }, [layout]);
70
- return (_jsx("div", { style: {
81
+ return (_jsxs("div", { className: cn("relative z-10 w-full max-w-md px-4 max-h-screen bg-cover bg-center bg-fixed overflow-hidden", className), style: {
71
82
  backgroundImage: `url('/images/jpg/${theme || "default"}_auth.jpeg')`,
72
- }, className: cn("z-10 w-full max-w-md px-4 max-h-screen bg-cover bg-center bg-fixed overflow-hidden", className), children: _jsx(RenderUi, { onSubmit: handleSubmit, errors: errors, message: message, theme: theme }) }));
83
+ }, children: [_jsx("div", { className: "absolute inset-0 bg-black pointer-events-none", style: {
84
+ opacity: overlayOpacity,
85
+ } }), _jsx("div", { className: "relative z-10", children: _jsx(RenderUi, { onSubmit: handleSubmit, errors: errors, message: message, theme: theme, translations: translations }) })] }));
73
86
  }
@@ -5,18 +5,19 @@
5
5
  * @Date: 2025-12-31 06:00:17
6
6
  * @Description: Login handler with Next.js native cookies
7
7
  */
8
+ import { cookies } from "next/headers";
8
9
  import { NextResponse } from "next/server";
9
10
  // Functions
10
11
  import { cns } from "forma-li";
11
12
  export function loginHandler(apiUrl) {
12
13
  return async function POST(req) {
13
- var _a, _b;
14
+ var _a, _b, _c, _d;
14
15
  try {
15
16
  const body = await req.json();
16
17
  const data = await cns({
17
18
  method: "post",
18
19
  endPoint: apiUrl,
19
- body: body,
20
+ body,
20
21
  route: "/login",
21
22
  });
22
23
  if (!data) {
@@ -26,10 +27,15 @@ export function loginHandler(apiUrl) {
26
27
  }, { status: 500 });
27
28
  }
28
29
  if (data.success && ((_b = (_a = data.data) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.access_token)) {
30
+ const cookieStore = await cookies();
31
+ const returnTo = (_c = cookieStore.get("returnTo")) === null || _c === void 0 ? void 0 : _c.value;
32
+ const lastVisited = (_d = cookieStore.get("lastVisited")) === null || _d === void 0 ? void 0 : _d.value;
33
+ const redirectTo = returnTo || lastVisited || "/";
29
34
  const res = NextResponse.json({
30
35
  message: "Login successful",
31
36
  success: true,
32
37
  user: data.data.user,
38
+ redirectTo,
33
39
  });
34
40
  const cookieOptions = {
35
41
  secure: process.env.NODE_ENV === "production",
@@ -39,9 +45,11 @@ export function loginHandler(apiUrl) {
39
45
  };
40
46
  res.cookies.set(Object.assign(Object.assign({ name: "app_key", value: JSON.stringify({
41
47
  tk: data.data.token.access_token,
42
- ud: data.data.user.uuid || data.data.user.id,
48
+ ud: data.data.user.uuid ||
49
+ data.data.user.id,
43
50
  }) }, cookieOptions), { httpOnly: false }));
44
- res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.token.token_type || "Bearer" }, cookieOptions), { httpOnly: false }));
51
+ res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.token.token_type ||
52
+ "Bearer" }, cookieOptions), { httpOnly: false }));
45
53
  res.cookies.set(Object.assign(Object.assign({ name: "user", value: JSON.stringify(data.data.user) }, cookieOptions), { httpOnly: false }));
46
54
  res.cookies.set(Object.assign(Object.assign({ name: "isLoggedIn", value: "true" }, cookieOptions), { httpOnly: false }));
47
55
  return res;
@@ -54,7 +62,8 @@ export function loginHandler(apiUrl) {
54
62
  catch (err) {
55
63
  console.error("Login error:", err);
56
64
  return NextResponse.json({
57
- message: err.message || "Internal server error",
65
+ message: err.message ||
66
+ "Internal server error",
58
67
  success: false,
59
68
  }, { status: 500 });
60
69
  }
@@ -13,19 +13,25 @@ export interface LoginProps {
13
13
  layout: string;
14
14
  theme?: string;
15
15
  className?: string;
16
+ overlayOpacity?: number;
16
17
  translations?: Partial<Record<Lang, Partial<Dictionary>>>;
17
18
  }
18
19
  export interface RegisterComponentProps {
19
20
  onSubmit: (formData: FormData) => void;
20
21
  errors?: {
22
+ name?: string;
21
23
  email?: string;
22
24
  password?: string;
25
+ confirmPassword?: string;
23
26
  };
24
27
  message?: string | null;
25
28
  theme?: string;
29
+ translations?: Partial<Record<Lang, Partial<Dictionary>>>;
26
30
  }
27
31
  export interface RegisterProps {
28
32
  layout: string;
29
33
  theme?: string;
30
34
  className?: string;
35
+ overlayOpacity?: number;
36
+ translations?: Partial<Record<Lang, Partial<Dictionary>>>;
31
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-auth-mfelfelani72",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [