next-auth-mfelfelani72 0.0.49 → 0.0.50
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,17 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
15
15
|
try {
|
|
16
16
|
const body = await req.json();
|
|
17
17
|
const { name, email, password, confirmPassword, } = body;
|
|
@@ -77,6 +77,7 @@ export function registerHandler(apiUrl) {
|
|
|
77
77
|
body: payload,
|
|
78
78
|
route: "/register",
|
|
79
79
|
});
|
|
80
|
+
console.log("REGISTER BACKEND RESPONSE:", data);
|
|
80
81
|
if (!data) {
|
|
81
82
|
return NextResponse.json({
|
|
82
83
|
message: "No response from server",
|
|
@@ -84,13 +85,18 @@ export function registerHandler(apiUrl) {
|
|
|
84
85
|
}, { status: 500 });
|
|
85
86
|
}
|
|
86
87
|
if (data.success &&
|
|
87
|
-
((
|
|
88
|
+
((_a = data.data) === null || _a === void 0 ? void 0 : _a.access_token)) {
|
|
88
89
|
const cookieStore = await cookies();
|
|
89
|
-
const returnTo = (
|
|
90
|
-
const lastVisited = (
|
|
90
|
+
const returnTo = (_b = cookieStore.get("returnTo")) === null || _b === void 0 ? void 0 : _b.value;
|
|
91
|
+
const lastVisited = (_c = cookieStore.get("lastVisited")) === null || _c === void 0 ? void 0 : _c.value;
|
|
91
92
|
const redirectTo = returnTo ||
|
|
92
93
|
lastVisited ||
|
|
93
94
|
"/";
|
|
95
|
+
console.log("AUTH REGISTER REDIRECT:", {
|
|
96
|
+
returnTo,
|
|
97
|
+
lastVisited,
|
|
98
|
+
redirectTo,
|
|
99
|
+
});
|
|
94
100
|
const res = NextResponse.json({
|
|
95
101
|
message: data.message ||
|
|
96
102
|
"Registration successful",
|
|
@@ -105,14 +111,18 @@ export function registerHandler(apiUrl) {
|
|
|
105
111
|
path: "/",
|
|
106
112
|
maxAge: 60 * 60 * 24 * 7,
|
|
107
113
|
};
|
|
114
|
+
// Auth token
|
|
108
115
|
res.cookies.set(Object.assign(Object.assign({ name: "app_key", value: JSON.stringify({
|
|
109
|
-
tk: data.data.
|
|
116
|
+
tk: data.data.access_token,
|
|
110
117
|
ud: data.data.user.uuid ||
|
|
111
118
|
data.data.user.id,
|
|
112
119
|
}) }, cookieOptions), { httpOnly: false }));
|
|
113
|
-
|
|
120
|
+
// Token type
|
|
121
|
+
res.cookies.set(Object.assign(Object.assign({ name: "key_type", value: data.data.token_type ||
|
|
114
122
|
"Bearer" }, cookieOptions), { httpOnly: false }));
|
|
123
|
+
// User
|
|
115
124
|
res.cookies.set(Object.assign(Object.assign({ name: "user", value: JSON.stringify(data.data.user) }, cookieOptions), { httpOnly: false }));
|
|
125
|
+
// Authentication state
|
|
116
126
|
res.cookies.set(Object.assign(Object.assign({ name: "isLoggedIn", value: "true" }, cookieOptions), { httpOnly: false }));
|
|
117
127
|
return res;
|
|
118
128
|
}
|