next-auth-mfelfelani72 0.0.52 → 0.0.54
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,5 +1,2 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
-
export declare function loginHandler(apiUrl: string): (req: NextRequest) => Promise<NextResponse<
|
|
3
|
-
message: any;
|
|
4
|
-
success: boolean;
|
|
5
|
-
}>>;
|
|
2
|
+
export declare function loginHandler(apiUrl: string): (req: NextRequest) => Promise<NextResponse<any>>;
|
|
@@ -31,12 +31,7 @@ export function loginHandler(apiUrl) {
|
|
|
31
31
|
const returnTo = (_c = cookieStore.get("returnTo")) === null || _c === void 0 ? void 0 : _c.value;
|
|
32
32
|
const lastVisited = (_d = cookieStore.get("lastVisited")) === null || _d === void 0 ? void 0 : _d.value;
|
|
33
33
|
const redirectTo = returnTo || lastVisited || "/";
|
|
34
|
-
const res = NextResponse.json({
|
|
35
|
-
message: "Login successful",
|
|
36
|
-
success: true,
|
|
37
|
-
user: data.data.user,
|
|
38
|
-
redirectTo,
|
|
39
|
-
});
|
|
34
|
+
const res = NextResponse.json(Object.assign(Object.assign({}, data), { redirectTo }));
|
|
40
35
|
const cookieOptions = {
|
|
41
36
|
secure: process.env.NODE_ENV === "production",
|
|
42
37
|
sameSite: "strict",
|
|
@@ -54,10 +49,7 @@ export function loginHandler(apiUrl) {
|
|
|
54
49
|
res.cookies.set(Object.assign(Object.assign({ name: "isLoggedIn", value: "true" }, cookieOptions), { httpOnly: false }));
|
|
55
50
|
return res;
|
|
56
51
|
}
|
|
57
|
-
return NextResponse.json({
|
|
58
|
-
message: data.message || "Login failed",
|
|
59
|
-
success: false,
|
|
60
|
-
}, { status: 401 });
|
|
52
|
+
return NextResponse.json(data, { status: 401 });
|
|
61
53
|
}
|
|
62
54
|
catch (err) {
|
|
63
55
|
console.error("Login error:", err);
|
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
-
export declare function registerHandler(apiUrl: string): (req: NextRequest) => Promise<NextResponse<
|
|
3
|
-
message: any;
|
|
4
|
-
success: boolean;
|
|
5
|
-
}>>;
|
|
2
|
+
export declare function registerHandler(apiUrl: string): (req: NextRequest) => Promise<NextResponse<any>>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @Author: Mohammad Felfelani
|
|
3
|
-
* @Email: mfelfelani72@gmail.com
|
|
4
|
-
* @Team:
|
|
5
|
-
* @Date: 2025-12-31 06:00:17
|
|
6
|
-
* @Description: Register handler with Next.js native cookies
|
|
7
|
-
*/
|
|
2
|
+
* @Author: Mohammad Felfelani
|
|
3
|
+
* @Email: mfelfelani72@gmail.com
|
|
4
|
+
* @Team:
|
|
5
|
+
* @Date: 2025-12-31 06:00:17
|
|
6
|
+
* @Description: Register handler with Next.js native cookies
|
|
7
|
+
*/
|
|
8
8
|
import { cookies } from "next/headers";
|
|
9
9
|
import { NextResponse, } from "next/server";
|
|
10
10
|
// Functions
|
|
11
11
|
import { cns } from "forma-li";
|
|
12
12
|
export function registerHandler(apiUrl) {
|
|
13
13
|
return async function POST(req) {
|
|
14
|
-
var _a, _b, _c;
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
15
|
try {
|
|
16
16
|
const body = await req.json();
|
|
17
17
|
const { name, email, password, confirmPassword, } = body;
|
|
@@ -85,10 +85,10 @@ export function registerHandler(apiUrl) {
|
|
|
85
85
|
}, { status: 500 });
|
|
86
86
|
}
|
|
87
87
|
if (data.success &&
|
|
88
|
-
((_a = data.data) === null || _a === void 0 ? void 0 : _a.access_token)) {
|
|
88
|
+
((_b = (_a = data.data) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.access_token)) {
|
|
89
89
|
const cookieStore = await cookies();
|
|
90
|
-
const returnTo = (
|
|
91
|
-
const lastVisited = (
|
|
90
|
+
const returnTo = (_c = cookieStore.get("returnTo")) === null || _c === void 0 ? void 0 : _c.value;
|
|
91
|
+
const lastVisited = (_d = cookieStore.get("lastVisited")) === null || _d === void 0 ? void 0 : _d.value;
|
|
92
92
|
const redirectTo = returnTo ||
|
|
93
93
|
lastVisited ||
|
|
94
94
|
"/";
|
|
@@ -97,13 +97,7 @@ export function registerHandler(apiUrl) {
|
|
|
97
97
|
lastVisited,
|
|
98
98
|
redirectTo,
|
|
99
99
|
});
|
|
100
|
-
const res = NextResponse.json({
|
|
101
|
-
message: data.message ||
|
|
102
|
-
"Registration successful",
|
|
103
|
-
success: true,
|
|
104
|
-
user: data.data.user,
|
|
105
|
-
redirectTo,
|
|
106
|
-
});
|
|
100
|
+
const res = NextResponse.json(Object.assign(Object.assign({}, data), { redirectTo }));
|
|
107
101
|
const cookieOptions = {
|
|
108
102
|
secure: process.env.NODE_ENV ===
|
|
109
103
|
"production",
|
|
@@ -113,12 +107,14 @@ export function registerHandler(apiUrl) {
|
|
|
113
107
|
};
|
|
114
108
|
// Auth token
|
|
115
109
|
res.cookies.set(Object.assign(Object.assign({ name: "app_key", value: JSON.stringify({
|
|
116
|
-
tk: data.data.
|
|
110
|
+
tk: data.data.token
|
|
111
|
+
.access_token,
|
|
117
112
|
ud: data.data.user.uuid ||
|
|
118
113
|
data.data.user.id,
|
|
119
114
|
}) }, cookieOptions), { httpOnly: false }));
|
|
120
115
|
// Token type
|
|
121
|
-
res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.
|
|
116
|
+
res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.token
|
|
117
|
+
.token_type ||
|
|
122
118
|
"Bearer" }, cookieOptions), { httpOnly: false }));
|
|
123
119
|
// User
|
|
124
120
|
res.cookies.set(Object.assign(Object.assign({ name: "user", value: JSON.stringify(data.data.user) }, cookieOptions), { httpOnly: false }));
|
|
@@ -126,12 +122,7 @@ export function registerHandler(apiUrl) {
|
|
|
126
122
|
res.cookies.set(Object.assign(Object.assign({ name: "isLoggedIn", value: "true" }, cookieOptions), { httpOnly: false }));
|
|
127
123
|
return res;
|
|
128
124
|
}
|
|
129
|
-
return NextResponse.json({
|
|
130
|
-
message: data.message ||
|
|
131
|
-
"Registration failed",
|
|
132
|
-
success: false,
|
|
133
|
-
errors: data.errors,
|
|
134
|
-
}, { status: 400 });
|
|
125
|
+
return NextResponse.json(data, { status: 400 });
|
|
135
126
|
}
|
|
136
127
|
catch (err) {
|
|
137
128
|
console.error("Registration error:", err);
|