next-auth-mfelfelani72 0.0.55 → 0.0.56
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.
package/README.md
CHANGED
|
File without changes
|
|
@@ -33,7 +33,8 @@ export function loginHandler(apiUrl) {
|
|
|
33
33
|
const redirectTo = returnTo || lastVisited || "/";
|
|
34
34
|
const res = NextResponse.json(Object.assign(Object.assign({}, data), { redirectTo }));
|
|
35
35
|
const cookieOptions = {
|
|
36
|
-
secure: process.env.NODE_ENV === "production",
|
|
36
|
+
// secure: process.env.NODE_ENV === "production",
|
|
37
|
+
secure: false,
|
|
37
38
|
sameSite: "strict",
|
|
38
39
|
path: "/",
|
|
39
40
|
maxAge: 60 * 60 * 24 * 7,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @Description: Register handler with Next.js native cookies
|
|
7
7
|
*/
|
|
8
8
|
import { cookies } from "next/headers";
|
|
9
|
-
import { NextResponse
|
|
9
|
+
import { NextResponse } from "next/server";
|
|
10
10
|
// Functions
|
|
11
11
|
import { cns } from "forma-li";
|
|
12
12
|
export function registerHandler(apiUrl) {
|
|
@@ -14,20 +14,14 @@ export function registerHandler(apiUrl) {
|
|
|
14
14
|
var _a, _b, _c, _d;
|
|
15
15
|
try {
|
|
16
16
|
const body = await req.json();
|
|
17
|
-
const { name, email, password, confirmPassword
|
|
18
|
-
if (!email ||
|
|
19
|
-
!password ||
|
|
20
|
-
!confirmPassword) {
|
|
17
|
+
const { name, email, password, confirmPassword } = body;
|
|
18
|
+
if (!email || !password || !confirmPassword) {
|
|
21
19
|
return NextResponse.json({
|
|
22
20
|
message: "Email and password are required",
|
|
23
21
|
success: false,
|
|
24
22
|
errors: {
|
|
25
|
-
email: !email
|
|
26
|
-
|
|
27
|
-
: undefined,
|
|
28
|
-
password: !password
|
|
29
|
-
? "Password is required"
|
|
30
|
-
: undefined,
|
|
23
|
+
email: !email ? "Email is required" : undefined,
|
|
24
|
+
password: !password ? "Password is required" : undefined,
|
|
31
25
|
confirmPassword: !confirmPassword
|
|
32
26
|
? "Confirm password is required"
|
|
33
27
|
: undefined,
|
|
@@ -62,8 +56,7 @@ export function registerHandler(apiUrl) {
|
|
|
62
56
|
}, { status: 400 });
|
|
63
57
|
}
|
|
64
58
|
const nameFromEmail = email.split("@")[0];
|
|
65
|
-
const displayName = nameFromEmail.charAt(0).toUpperCase() +
|
|
66
|
-
nameFromEmail.slice(1);
|
|
59
|
+
const displayName = nameFromEmail.charAt(0).toUpperCase() + nameFromEmail.slice(1);
|
|
67
60
|
const payload = {
|
|
68
61
|
name: displayName,
|
|
69
62
|
email: email.trim().toLowerCase(),
|
|
@@ -84,14 +77,11 @@ export function registerHandler(apiUrl) {
|
|
|
84
77
|
success: false,
|
|
85
78
|
}, { status: 500 });
|
|
86
79
|
}
|
|
87
|
-
if (data.success &&
|
|
88
|
-
((_b = (_a = data.data) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.access_token)) {
|
|
80
|
+
if (data.success && ((_b = (_a = data.data) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.access_token)) {
|
|
89
81
|
const cookieStore = await cookies();
|
|
90
82
|
const returnTo = (_c = cookieStore.get("returnTo")) === null || _c === void 0 ? void 0 : _c.value;
|
|
91
83
|
const lastVisited = (_d = cookieStore.get("lastVisited")) === null || _d === void 0 ? void 0 : _d.value;
|
|
92
|
-
const redirectTo = returnTo ||
|
|
93
|
-
lastVisited ||
|
|
94
|
-
"/";
|
|
84
|
+
const redirectTo = returnTo || lastVisited || "/";
|
|
95
85
|
console.log("AUTH REGISTER REDIRECT:", {
|
|
96
86
|
returnTo,
|
|
97
87
|
lastVisited,
|
|
@@ -99,23 +89,20 @@ export function registerHandler(apiUrl) {
|
|
|
99
89
|
});
|
|
100
90
|
const res = NextResponse.json(Object.assign(Object.assign({}, data), { redirectTo }));
|
|
101
91
|
const cookieOptions = {
|
|
102
|
-
secure:
|
|
103
|
-
|
|
92
|
+
secure: false,
|
|
93
|
+
// process.env.NODE_ENV ===
|
|
94
|
+
// "production",
|
|
104
95
|
sameSite: "strict",
|
|
105
96
|
path: "/",
|
|
106
97
|
maxAge: 60 * 60 * 24 * 7,
|
|
107
98
|
};
|
|
108
99
|
// Auth token
|
|
109
100
|
res.cookies.set(Object.assign(Object.assign({ name: "app_key", value: JSON.stringify({
|
|
110
|
-
tk: data.data.token
|
|
111
|
-
|
|
112
|
-
ud: data.data.user.uuid ||
|
|
113
|
-
data.data.user.id,
|
|
101
|
+
tk: data.data.token.access_token,
|
|
102
|
+
ud: data.data.user.uuid || data.data.user.id,
|
|
114
103
|
}) }, cookieOptions), { httpOnly: false }));
|
|
115
104
|
// Token type
|
|
116
|
-
res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.token
|
|
117
|
-
.token_type ||
|
|
118
|
-
"Bearer" }, cookieOptions), { httpOnly: false }));
|
|
105
|
+
res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.token.token_type || "Bearer" }, cookieOptions), { httpOnly: false }));
|
|
119
106
|
// User
|
|
120
107
|
res.cookies.set(Object.assign(Object.assign({ name: "user", value: JSON.stringify(data.data.user) }, cookieOptions), { httpOnly: false }));
|
|
121
108
|
// Authentication state
|
|
@@ -127,8 +114,7 @@ export function registerHandler(apiUrl) {
|
|
|
127
114
|
catch (err) {
|
|
128
115
|
console.error("Registration error:", err);
|
|
129
116
|
return NextResponse.json({
|
|
130
|
-
message: err.message ||
|
|
131
|
-
"Internal server error",
|
|
117
|
+
message: err.message || "Internal server error",
|
|
132
118
|
success: false,
|
|
133
119
|
}, { status: 500 });
|
|
134
120
|
}
|