@neondatabase/auth 0.1.0-beta.2 → 0.1.0-beta.21
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 +112 -18
- package/dist/{adapter-core-BDOw-gBC.mjs → adapter-core-PD5NQpLE.mjs} +392 -69
- package/dist/{adapter-core-C12KoaiU.d.mts → adapter-core-y53SWo8w.d.mts} +181 -627
- package/dist/{better-auth-react-adapter-FnBHa2nr.mjs → better-auth-react-adapter-B0XIXPUH.mjs} +10 -8
- package/dist/better-auth-react-adapter-B7zoQmoL.d.mts +2170 -0
- package/dist/chunk-VCZJYX65-CLnrj1o7-D6ZQkcc_.mjs +543 -0
- package/dist/constants-2bpp2_-f.mjs +30 -0
- package/dist/index.d.mts +4 -98
- package/dist/index.mjs +2 -1
- package/dist/{neon-auth-C9XTFffv.mjs → neon-auth-DUbqaO2v.mjs} +7 -4
- package/dist/neon-auth-oDgy6lQm.d.mts +107 -0
- package/dist/next/index.d.mts +76 -303
- package/dist/next/index.mjs +6 -174
- package/dist/next/server/index.d.mts +433 -0
- package/dist/next/server/index.mjs +731 -0
- package/dist/react/adapters/index.d.mts +4 -4
- package/dist/react/adapters/index.mjs +2 -1
- package/dist/react/index.d.mts +5 -5
- package/dist/react/index.mjs +5 -92
- package/dist/react/ui/index.d.mts +1 -1
- package/dist/react/ui/index.mjs +3 -91
- package/dist/react/ui/server.mjs +1 -1
- package/dist/{supabase-adapter-ggmqWgPe.mjs → supabase-adapter-Bdw6aPGx.mjs} +72 -167
- package/dist/supabase-adapter-Dm56RKRF.d.mts +2258 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.mjs +3 -0
- package/dist/ui/.safelist.html +3 -0
- package/dist/ui/css.css +2 -2
- package/dist/ui/tailwind.css +4 -3
- package/dist/ui/theme-inline.css +44 -0
- package/dist/ui/theme.css +221 -118
- package/dist/ui-CrxGg6vQ.mjs +12113 -0
- package/dist/vanilla/adapters/index.d.mts +3 -3
- package/dist/vanilla/adapters/index.mjs +2 -1
- package/dist/vanilla/index.d.mts +3 -3
- package/dist/vanilla/index.mjs +2 -1
- package/llms.txt +172 -0
- package/package.json +22 -11
- package/dist/better-auth-react-adapter-BXL48HIU.d.mts +0 -722
- package/dist/supabase-adapter-crabDnl2.d.mts +0 -128
- package/dist/ui-CNFBSekF.mjs +0 -401
- /package/dist/{adapters-Dkx0zoMR.mjs → adapters-B7YKkjaL.mjs} +0 -0
- /package/dist/{index-C-svZlpj.d.mts → index-CPnFzULh.d.mts} +0 -0
- /package/dist/{index-DuDD6cIY.d.mts → index-CzsGMS7C.d.mts} +0 -0
- /package/dist/{index-UW23fDSn.d.mts → index-OEBbnNdr.d.mts} +0 -0
package/dist/next/index.mjs
CHANGED
|
@@ -1,179 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import "../adapter-core-PD5NQpLE.mjs";
|
|
2
|
+
import { t as BetterAuthReactAdapter } from "../better-auth-react-adapter-B0XIXPUH.mjs";
|
|
3
|
+
import { t as createAuthClient$1 } from "../neon-auth-DUbqaO2v.mjs";
|
|
4
4
|
|
|
5
|
-
//#region src/next/constants.ts
|
|
6
|
-
const NEON_AUTH_COOKIE_PREFIX = "__Secure-neon-auth";
|
|
7
|
-
const NEON_AUTH_SESSION_COOKIE_NAME = `${NEON_AUTH_COOKIE_PREFIX}.session_token`;
|
|
8
|
-
const NEON_AUTH_SESSION_CHALLENGE_COOKIE_NAME = `${NEON_AUTH_COOKIE_PREFIX}.session_challange`;
|
|
9
|
-
/** Name of the session verifier parameter in the URL, used for the OAUTH flow */
|
|
10
|
-
const NEON_AUTH_SESSION_VERIFIER_PARAM_NAME = "neon_auth_session_verifier";
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/next/handler/request.ts
|
|
14
|
-
const PROXY_HEADERS = [
|
|
15
|
-
"user-agent",
|
|
16
|
-
"authorization",
|
|
17
|
-
"referer"
|
|
18
|
-
];
|
|
19
|
-
const handleAuthRequest = async (baseUrl, request, path) => {
|
|
20
|
-
const upstreamURL = `${baseUrl}/${path}${new URL(request.url).search}`;
|
|
21
|
-
const headers = prepareRequestHeaders(request);
|
|
22
|
-
const body = await parseRequestBody(request);
|
|
23
|
-
try {
|
|
24
|
-
return await fetch(upstreamURL, {
|
|
25
|
-
method: request.method,
|
|
26
|
-
headers,
|
|
27
|
-
body
|
|
28
|
-
});
|
|
29
|
-
} catch (error) {
|
|
30
|
-
const message = error instanceof Error ? error.message : "Internal Server Error";
|
|
31
|
-
console.error(`[AuthError] ${message}`, error);
|
|
32
|
-
return new Response(`[AuthError] ${message}`, { status: 500 });
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const prepareRequestHeaders = (request) => {
|
|
36
|
-
const headers = new Headers();
|
|
37
|
-
headers.set("Content-Type", "application/json");
|
|
38
|
-
for (const header of PROXY_HEADERS) if (request.headers.get(header)) headers.set(header, request.headers.get(header));
|
|
39
|
-
headers.set("Origin", getOrigin(request));
|
|
40
|
-
headers.set("Cookie", extractRequestCookies(request.headers));
|
|
41
|
-
headers.set("X-Neon-Auth-Next", "true");
|
|
42
|
-
return headers;
|
|
43
|
-
};
|
|
44
|
-
const getOrigin = (request) => {
|
|
45
|
-
return request.headers.get("origin") || request.headers.get("referer")?.split("/").slice(0, 3).join("/") || new URL(request.url).origin;
|
|
46
|
-
};
|
|
47
|
-
const extractRequestCookies = (headers) => {
|
|
48
|
-
const cookieHeader = headers.get("cookie");
|
|
49
|
-
if (!cookieHeader) return "";
|
|
50
|
-
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
51
|
-
const result = [];
|
|
52
|
-
for (const cookie of cookies) {
|
|
53
|
-
const [name] = cookie.split("=");
|
|
54
|
-
if (name.startsWith(NEON_AUTH_COOKIE_PREFIX)) result.push(cookie);
|
|
55
|
-
}
|
|
56
|
-
return result.join(";");
|
|
57
|
-
};
|
|
58
|
-
const parseRequestBody = async (request) => {
|
|
59
|
-
if (request.body) return request.text();
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/next/handler/response.ts
|
|
64
|
-
const RESPONSE_HEADERS_ALLOWLIST = [
|
|
65
|
-
"content-type",
|
|
66
|
-
"content-length",
|
|
67
|
-
"content-encoding",
|
|
68
|
-
"transfer-encoding",
|
|
69
|
-
"connection",
|
|
70
|
-
"date",
|
|
71
|
-
"set-cookie",
|
|
72
|
-
"set-auth-jwt",
|
|
73
|
-
"set-auth-token",
|
|
74
|
-
"x-neon-ret-request-id"
|
|
75
|
-
];
|
|
76
|
-
const handleAuthResponse = async (response) => {
|
|
77
|
-
return new Response(response.body, {
|
|
78
|
-
status: response.status,
|
|
79
|
-
statusText: response.statusText,
|
|
80
|
-
headers: prepareResponseHeaders(response)
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
const prepareResponseHeaders = (response) => {
|
|
84
|
-
const headers = new Headers();
|
|
85
|
-
for (const header of RESPONSE_HEADERS_ALLOWLIST) {
|
|
86
|
-
const value = response.headers.get(header);
|
|
87
|
-
if (value) headers.set(header, value);
|
|
88
|
-
}
|
|
89
|
-
return headers;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/next/handler/index.ts
|
|
94
|
-
const toNextJsHandler = (baseUrl) => {
|
|
95
|
-
const baseURL = baseUrl || process.env.NEON_AUTH_BASE_URL;
|
|
96
|
-
if (!baseURL) throw new Error("You must provide a Neon Auth base URL in the handler options or in the environment variables");
|
|
97
|
-
const handler = async (request, { params }) => {
|
|
98
|
-
return await handleAuthResponse(await handleAuthRequest(baseURL, request, (await params).path.join("/")));
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
GET: handler,
|
|
102
|
-
POST: handler,
|
|
103
|
-
PUT: handler,
|
|
104
|
-
DELETE: handler,
|
|
105
|
-
PATCH: handler
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/next/middleware/oauth.ts
|
|
111
|
-
const needsSessionVerification = (request) => {
|
|
112
|
-
const hasVerifier = request.nextUrl.searchParams.has(NEON_AUTH_SESSION_VERIFIER_PARAM_NAME);
|
|
113
|
-
const hasChallenge = request.cookies.get(NEON_AUTH_SESSION_CHALLENGE_COOKIE_NAME);
|
|
114
|
-
const hasSession = request.cookies.get(NEON_AUTH_SESSION_COOKIE_NAME);
|
|
115
|
-
return hasVerifier && hasChallenge && !hasSession;
|
|
116
|
-
};
|
|
117
|
-
const verifySession = async (request, baseUrl) => {
|
|
118
|
-
const url = request.nextUrl;
|
|
119
|
-
const verifier = url.searchParams.get(NEON_AUTH_SESSION_VERIFIER_PARAM_NAME);
|
|
120
|
-
const challenge = request.cookies.get(NEON_AUTH_SESSION_CHALLENGE_COOKIE_NAME);
|
|
121
|
-
if (!verifier || !challenge) return null;
|
|
122
|
-
const response = await getSession(request, baseUrl);
|
|
123
|
-
if (response.ok) {
|
|
124
|
-
const headers = new Headers();
|
|
125
|
-
const cookies = extractResponseCookies(response.headers);
|
|
126
|
-
for (const cookie of cookies) headers.append("Set-Cookie", cookie);
|
|
127
|
-
url.searchParams.delete(NEON_AUTH_SESSION_VERIFIER_PARAM_NAME);
|
|
128
|
-
return NextResponse.redirect(url, { headers });
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
};
|
|
132
|
-
const getSession = async (request, baseUrl) => {
|
|
133
|
-
return handleAuthResponse(await handleAuthRequest(baseUrl, new Request(request.url, {
|
|
134
|
-
method: "GET",
|
|
135
|
-
headers: request.headers,
|
|
136
|
-
body: null
|
|
137
|
-
}), "get-session"));
|
|
138
|
-
};
|
|
139
|
-
const extractResponseCookies = (headers) => {
|
|
140
|
-
const cookieHeader = headers.get("set-cookie");
|
|
141
|
-
if (!cookieHeader) return [];
|
|
142
|
-
return cookieHeader.split(", ").map((c) => c.trim());
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
//#endregion
|
|
146
|
-
//#region src/next/middleware/index.ts
|
|
147
|
-
const SKIP_ROUTES = [
|
|
148
|
-
"/api/auth",
|
|
149
|
-
"/auth/callback",
|
|
150
|
-
"/auth/sign-in",
|
|
151
|
-
"/auth/sign-up",
|
|
152
|
-
"/auth/magic-link",
|
|
153
|
-
"/auth/email-otp",
|
|
154
|
-
"/auth/forgot-password"
|
|
155
|
-
];
|
|
156
|
-
const neonAuthMiddleware = ({ loginUrl = "/auth/sign-in", authBaseUrl }) => {
|
|
157
|
-
const baseURL = authBaseUrl || process.env.NEON_AUTH_BASE_URL;
|
|
158
|
-
if (!baseURL) throw new Error("You must provide a Neon Auth base URL in the middleware options or in the environment variables");
|
|
159
|
-
return async (request) => {
|
|
160
|
-
const { pathname } = request.nextUrl;
|
|
161
|
-
if (pathname.startsWith(loginUrl)) return NextResponse.next();
|
|
162
|
-
if (needsSessionVerification(request)) {
|
|
163
|
-
const response = await verifySession(request, baseURL);
|
|
164
|
-
if (response !== null) return response;
|
|
165
|
-
}
|
|
166
|
-
if (SKIP_ROUTES.some((route) => pathname.startsWith(route))) return NextResponse.next();
|
|
167
|
-
if (!request.cookies.get(NEON_AUTH_SESSION_COOKIE_NAME)) return NextResponse.redirect(new URL(loginUrl, request.url));
|
|
168
|
-
return NextResponse.next();
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
5
|
//#region src/next/index.ts
|
|
174
|
-
|
|
6
|
+
function createAuthClient() {
|
|
175
7
|
return createAuthClient$1(void 0, { adapter: BetterAuthReactAdapter() });
|
|
176
|
-
}
|
|
8
|
+
}
|
|
177
9
|
|
|
178
10
|
//#endregion
|
|
179
|
-
export { createAuthClient
|
|
11
|
+
export { createAuthClient };
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { O as BetterAuthSession, k as BetterAuthUser } from "../../adapter-core-y53SWo8w.mjs";
|
|
2
|
+
import "../../better-auth-react-adapter-B7zoQmoL.mjs";
|
|
3
|
+
import "../../supabase-adapter-Dm56RKRF.mjs";
|
|
4
|
+
import { o as VanillaBetterAuthClient } from "../../neon-auth-oDgy6lQm.mjs";
|
|
5
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
6
|
+
|
|
7
|
+
//#region src/server/endpoints.d.ts
|
|
8
|
+
|
|
9
|
+
declare const API_ENDPOINTS: {
|
|
10
|
+
readonly getSession: {
|
|
11
|
+
readonly path: "get-session";
|
|
12
|
+
readonly method: "GET";
|
|
13
|
+
};
|
|
14
|
+
readonly getAccessToken: {
|
|
15
|
+
readonly path: "get-access-token";
|
|
16
|
+
readonly method: "GET";
|
|
17
|
+
};
|
|
18
|
+
readonly listSessions: {
|
|
19
|
+
readonly path: "list-sessions";
|
|
20
|
+
readonly method: "GET";
|
|
21
|
+
};
|
|
22
|
+
readonly revokeSession: {
|
|
23
|
+
readonly path: "revoke-session";
|
|
24
|
+
readonly method: "POST";
|
|
25
|
+
};
|
|
26
|
+
readonly revokeSessions: {
|
|
27
|
+
readonly path: "revoke-sessions";
|
|
28
|
+
readonly method: "POST";
|
|
29
|
+
};
|
|
30
|
+
readonly revokeOtherSessions: {
|
|
31
|
+
readonly path: "revoke-all-sessions";
|
|
32
|
+
readonly method: "POST";
|
|
33
|
+
};
|
|
34
|
+
readonly refreshToken: {
|
|
35
|
+
readonly path: "refresh-token";
|
|
36
|
+
readonly method: "POST";
|
|
37
|
+
};
|
|
38
|
+
readonly signIn: {
|
|
39
|
+
readonly email: {
|
|
40
|
+
readonly path: "sign-in/email";
|
|
41
|
+
readonly method: "POST";
|
|
42
|
+
};
|
|
43
|
+
readonly social: {
|
|
44
|
+
readonly path: "sign-in/social";
|
|
45
|
+
readonly method: "POST";
|
|
46
|
+
};
|
|
47
|
+
readonly emailOtp: {
|
|
48
|
+
readonly path: "sign-in/email-otp";
|
|
49
|
+
readonly method: "POST";
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly signUp: {
|
|
53
|
+
readonly email: {
|
|
54
|
+
readonly path: "sign-up/email";
|
|
55
|
+
readonly method: "POST";
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
readonly signOut: {
|
|
59
|
+
readonly path: "sign-out";
|
|
60
|
+
readonly method: "POST";
|
|
61
|
+
};
|
|
62
|
+
readonly listAccounts: {
|
|
63
|
+
readonly path: "list-accounts";
|
|
64
|
+
readonly method: "GET";
|
|
65
|
+
};
|
|
66
|
+
readonly accountInfo: {
|
|
67
|
+
readonly path: "account-info";
|
|
68
|
+
readonly method: "GET";
|
|
69
|
+
};
|
|
70
|
+
readonly updateUser: {
|
|
71
|
+
readonly path: "update-user";
|
|
72
|
+
readonly method: "POST";
|
|
73
|
+
};
|
|
74
|
+
readonly deleteUser: {
|
|
75
|
+
readonly path: "delete-user";
|
|
76
|
+
readonly method: "POST";
|
|
77
|
+
};
|
|
78
|
+
readonly changePassword: {
|
|
79
|
+
readonly path: "change-password";
|
|
80
|
+
readonly method: "POST";
|
|
81
|
+
};
|
|
82
|
+
readonly sendVerificationEmail: {
|
|
83
|
+
readonly path: "send-verification-email";
|
|
84
|
+
readonly method: "POST";
|
|
85
|
+
};
|
|
86
|
+
readonly verifyEmail: {
|
|
87
|
+
readonly path: "verify-email";
|
|
88
|
+
readonly method: "POST";
|
|
89
|
+
};
|
|
90
|
+
readonly resetPassword: {
|
|
91
|
+
readonly path: "reset-password";
|
|
92
|
+
readonly method: "POST";
|
|
93
|
+
};
|
|
94
|
+
readonly requestPasswordReset: {
|
|
95
|
+
readonly path: "request-password-reset";
|
|
96
|
+
readonly method: "POST";
|
|
97
|
+
};
|
|
98
|
+
readonly token: {
|
|
99
|
+
readonly path: "token";
|
|
100
|
+
readonly method: "GET";
|
|
101
|
+
};
|
|
102
|
+
readonly jwks: {
|
|
103
|
+
readonly path: "jwt";
|
|
104
|
+
readonly method: "GET";
|
|
105
|
+
};
|
|
106
|
+
readonly getAnonymousToken: {
|
|
107
|
+
readonly path: "token/anonymous";
|
|
108
|
+
readonly method: "GET";
|
|
109
|
+
};
|
|
110
|
+
readonly admin: {
|
|
111
|
+
readonly createUser: {
|
|
112
|
+
readonly path: "admin/create-user";
|
|
113
|
+
readonly method: "POST";
|
|
114
|
+
};
|
|
115
|
+
readonly listUsers: {
|
|
116
|
+
readonly path: "admin/list-users";
|
|
117
|
+
readonly method: "GET";
|
|
118
|
+
};
|
|
119
|
+
readonly setRole: {
|
|
120
|
+
readonly path: "admin/set-role";
|
|
121
|
+
readonly method: "POST";
|
|
122
|
+
};
|
|
123
|
+
readonly setUserPassword: {
|
|
124
|
+
readonly path: "admin/set-user-password";
|
|
125
|
+
readonly method: "POST";
|
|
126
|
+
};
|
|
127
|
+
readonly updateUser: {
|
|
128
|
+
readonly path: "admin/update-user";
|
|
129
|
+
readonly method: "POST";
|
|
130
|
+
};
|
|
131
|
+
readonly banUser: {
|
|
132
|
+
readonly path: "admin/ban-user";
|
|
133
|
+
readonly method: "POST";
|
|
134
|
+
};
|
|
135
|
+
readonly unbanUser: {
|
|
136
|
+
readonly path: "admin/unban-user";
|
|
137
|
+
readonly method: "POST";
|
|
138
|
+
};
|
|
139
|
+
readonly listUserSessions: {
|
|
140
|
+
readonly path: "admin/list-user-sessions";
|
|
141
|
+
readonly method: "GET";
|
|
142
|
+
};
|
|
143
|
+
readonly revokeUserSession: {
|
|
144
|
+
readonly path: "admin/revoke-user-session";
|
|
145
|
+
readonly method: "POST";
|
|
146
|
+
};
|
|
147
|
+
readonly revokeUserSessions: {
|
|
148
|
+
readonly path: "admin/revoke-user-sessions";
|
|
149
|
+
readonly method: "POST";
|
|
150
|
+
};
|
|
151
|
+
readonly impersonateUser: {
|
|
152
|
+
readonly path: "admin/impersonate-user";
|
|
153
|
+
readonly method: "POST";
|
|
154
|
+
};
|
|
155
|
+
readonly stopImpersonating: {
|
|
156
|
+
readonly path: "admin/stop-impersonating";
|
|
157
|
+
readonly method: "POST";
|
|
158
|
+
};
|
|
159
|
+
readonly removeUser: {
|
|
160
|
+
readonly path: "admin/remove-user";
|
|
161
|
+
readonly method: "POST";
|
|
162
|
+
};
|
|
163
|
+
readonly hasPermission: {
|
|
164
|
+
readonly path: "admin/has-permission";
|
|
165
|
+
readonly method: "POST";
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
readonly organization: {
|
|
169
|
+
readonly create: {
|
|
170
|
+
readonly path: "organization/create";
|
|
171
|
+
readonly method: "POST";
|
|
172
|
+
};
|
|
173
|
+
readonly update: {
|
|
174
|
+
readonly path: "organization/update";
|
|
175
|
+
readonly method: "POST";
|
|
176
|
+
};
|
|
177
|
+
readonly delete: {
|
|
178
|
+
readonly path: "organization/delete";
|
|
179
|
+
readonly method: "POST";
|
|
180
|
+
};
|
|
181
|
+
readonly list: {
|
|
182
|
+
readonly path: "organization/list";
|
|
183
|
+
readonly method: "GET";
|
|
184
|
+
};
|
|
185
|
+
readonly getFullOrganization: {
|
|
186
|
+
readonly path: "organization/get-full-organization";
|
|
187
|
+
readonly method: "GET";
|
|
188
|
+
};
|
|
189
|
+
readonly setActive: {
|
|
190
|
+
readonly path: "organization/set-active";
|
|
191
|
+
readonly method: "POST";
|
|
192
|
+
};
|
|
193
|
+
readonly checkSlug: {
|
|
194
|
+
readonly path: "organization/check-slug";
|
|
195
|
+
readonly method: "GET";
|
|
196
|
+
};
|
|
197
|
+
readonly listMembers: {
|
|
198
|
+
readonly path: "organization/list-members";
|
|
199
|
+
readonly method: "GET";
|
|
200
|
+
};
|
|
201
|
+
readonly removeMember: {
|
|
202
|
+
readonly path: "organization/remove-member";
|
|
203
|
+
readonly method: "POST";
|
|
204
|
+
};
|
|
205
|
+
readonly updateMemberRole: {
|
|
206
|
+
readonly path: "organization/update-member-role";
|
|
207
|
+
readonly method: "POST";
|
|
208
|
+
};
|
|
209
|
+
readonly leave: {
|
|
210
|
+
readonly path: "organization/leave";
|
|
211
|
+
readonly method: "POST";
|
|
212
|
+
};
|
|
213
|
+
readonly getActiveMember: {
|
|
214
|
+
readonly path: "organization/get-active-member";
|
|
215
|
+
readonly method: "GET";
|
|
216
|
+
};
|
|
217
|
+
readonly getActiveMemberRole: {
|
|
218
|
+
readonly path: "organization/get-active-member-role";
|
|
219
|
+
readonly method: "GET";
|
|
220
|
+
};
|
|
221
|
+
readonly inviteMember: {
|
|
222
|
+
readonly path: "organization/invite-member";
|
|
223
|
+
readonly method: "POST";
|
|
224
|
+
};
|
|
225
|
+
readonly acceptInvitation: {
|
|
226
|
+
readonly path: "organization/accept-invitation";
|
|
227
|
+
readonly method: "POST";
|
|
228
|
+
};
|
|
229
|
+
readonly rejectInvitation: {
|
|
230
|
+
readonly path: "organization/reject-invitation";
|
|
231
|
+
readonly method: "POST";
|
|
232
|
+
};
|
|
233
|
+
readonly cancelInvitation: {
|
|
234
|
+
readonly path: "organization/cancel-invitation";
|
|
235
|
+
readonly method: "POST";
|
|
236
|
+
};
|
|
237
|
+
readonly getInvitation: {
|
|
238
|
+
readonly path: "organization/get-invitation";
|
|
239
|
+
readonly method: "GET";
|
|
240
|
+
};
|
|
241
|
+
readonly listInvitations: {
|
|
242
|
+
readonly path: "organization/list-invitations";
|
|
243
|
+
readonly method: "GET";
|
|
244
|
+
};
|
|
245
|
+
readonly listUserInvitations: {
|
|
246
|
+
readonly path: "organization/list-user-invitations";
|
|
247
|
+
readonly method: "GET";
|
|
248
|
+
};
|
|
249
|
+
readonly hasPermission: {
|
|
250
|
+
readonly path: "organization/has-permission";
|
|
251
|
+
readonly method: "POST";
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
readonly emailOtp: {
|
|
255
|
+
readonly sendVerificationOtp: {
|
|
256
|
+
readonly path: "email-otp/send-verification-otp";
|
|
257
|
+
readonly method: "POST";
|
|
258
|
+
};
|
|
259
|
+
readonly verifyEmail: {
|
|
260
|
+
readonly path: "email-otp/verify-email";
|
|
261
|
+
readonly method: "POST";
|
|
262
|
+
};
|
|
263
|
+
readonly checkVerificationOtp: {
|
|
264
|
+
readonly path: "email-otp/check-verification-otp";
|
|
265
|
+
readonly method: "POST";
|
|
266
|
+
};
|
|
267
|
+
readonly resetPassword: {
|
|
268
|
+
readonly path: "email-otp/passcode";
|
|
269
|
+
readonly method: "POST";
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/server/types.d.ts
|
|
275
|
+
/**
|
|
276
|
+
* Extract top-level keys from API_ENDPOINTS.
|
|
277
|
+
* For nested endpoints like signIn.email, this extracts 'signIn' (not 'email').
|
|
278
|
+
*/
|
|
279
|
+
type TopLevelEndpointKeys<T> = { [K in keyof T]: K }[keyof T];
|
|
280
|
+
type ServerAuthMethods = TopLevelEndpointKeys<typeof API_ENDPOINTS>;
|
|
281
|
+
type NeonAuthServer = Pick<VanillaBetterAuthClient, ServerAuthMethods>;
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/next/auth/session.d.ts
|
|
284
|
+
type SessionData = {
|
|
285
|
+
session: BetterAuthSession;
|
|
286
|
+
user: BetterAuthUser;
|
|
287
|
+
} | {
|
|
288
|
+
session: null;
|
|
289
|
+
user: null;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* A utility function to be used in react server components fetch the session details from the Neon Auth API, if session token is available in cookie.
|
|
293
|
+
*
|
|
294
|
+
* @returns - `{ session: Session, user: User }` | `{ session: null, user: null}`.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* import { neonAuth } from "@neondatabase/auth/next/server"
|
|
299
|
+
*
|
|
300
|
+
* const { session, user } = await neonAuth()
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
declare const neonAuth: () => Promise<SessionData>;
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/next/middleware/index.d.ts
|
|
306
|
+
type NeonAuthMiddlewareOptions = {
|
|
307
|
+
loginUrl?: string;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* A Next.js middleware to protect routes from unauthenticated requests and refresh the session if required.
|
|
311
|
+
*
|
|
312
|
+
* @param loginUrl - The URL to redirect to when the user is not authenticated.
|
|
313
|
+
* @returns A middleware function that can be used in the Next.js app.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* import { neonAuthMiddleware } from "@neondatabase/auth/next"
|
|
318
|
+
*
|
|
319
|
+
* export default neonAuthMiddleware({
|
|
320
|
+
* loginUrl: '/auth/sign-in',
|
|
321
|
+
* });
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare function neonAuthMiddleware({
|
|
325
|
+
loginUrl
|
|
326
|
+
}: NeonAuthMiddlewareOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/next/handler/index.d.ts
|
|
329
|
+
type Params = {
|
|
330
|
+
path: string[];
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
*
|
|
334
|
+
* An API route handler to handle the auth requests from the client and proxy them to the Neon Auth.
|
|
335
|
+
*
|
|
336
|
+
* @returns A Next.js API handler functions those can be used in a Next.js route.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* Mount the `authApiHandler` to an API route. Create a route file inside `/api/auth/[...all]/route.ts` directory.
|
|
340
|
+
* And add the following code:
|
|
341
|
+
*
|
|
342
|
+
* ```ts
|
|
343
|
+
* // app/api/auth/[...all]/route.ts
|
|
344
|
+
* import { authApiHandler } from '@neondatabase/auth/next';
|
|
345
|
+
*
|
|
346
|
+
* export const { GET, POST } = authApiHandler();
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
declare function authApiHandler(): {
|
|
350
|
+
GET: (request: Request, {
|
|
351
|
+
params
|
|
352
|
+
}: {
|
|
353
|
+
params: Promise<Params>;
|
|
354
|
+
}) => Promise<Response>;
|
|
355
|
+
POST: (request: Request, {
|
|
356
|
+
params
|
|
357
|
+
}: {
|
|
358
|
+
params: Promise<Params>;
|
|
359
|
+
}) => Promise<Response>;
|
|
360
|
+
PUT: (request: Request, {
|
|
361
|
+
params
|
|
362
|
+
}: {
|
|
363
|
+
params: Promise<Params>;
|
|
364
|
+
}) => Promise<Response>;
|
|
365
|
+
DELETE: (request: Request, {
|
|
366
|
+
params
|
|
367
|
+
}: {
|
|
368
|
+
params: Promise<Params>;
|
|
369
|
+
}) => Promise<Response>;
|
|
370
|
+
PATCH: (request: Request, {
|
|
371
|
+
params
|
|
372
|
+
}: {
|
|
373
|
+
params: Promise<Params>;
|
|
374
|
+
}) => Promise<Response>;
|
|
375
|
+
};
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/next/server/index.d.ts
|
|
378
|
+
/**
|
|
379
|
+
* Creates a server-side auth API client for Next.js.
|
|
380
|
+
*
|
|
381
|
+
* This client exposes the Neon Auth APIs including authentication, user management, organizations, and admin operations.
|
|
382
|
+
*
|
|
383
|
+
* **Where to use:**
|
|
384
|
+
* - React Server Components
|
|
385
|
+
* - Server Actions
|
|
386
|
+
* - Route Handlers
|
|
387
|
+
*
|
|
388
|
+
* **Requirements:**
|
|
389
|
+
* - `NEON_AUTH_BASE_URL` environment variable must be set
|
|
390
|
+
* - Cookies are automatically read/written via `next/headers`
|
|
391
|
+
*
|
|
392
|
+
* @returns Auth server API client for Next.js
|
|
393
|
+
* @throws Error if `NEON_AUTH_BASE_URL` environment variable is not set
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```typescript
|
|
397
|
+
* // lib/auth/server.ts - Create a singleton instance
|
|
398
|
+
* import { createAuthServer } from '@neondatabase/auth/next/server';
|
|
399
|
+
* export const authServer = createAuthServer();
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* // Server Component - Reading session
|
|
405
|
+
* import { authServer } from '@/lib/auth/server';
|
|
406
|
+
*
|
|
407
|
+
* export default async function Page() {
|
|
408
|
+
* const { data: session } = await authServer.getSession();
|
|
409
|
+
* if (!session?.user) return <div>Not logged in</div>;
|
|
410
|
+
* return <div>Hello {session.user.name}</div>;
|
|
411
|
+
* }
|
|
412
|
+
* ```
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* // Server Action - Sign in
|
|
417
|
+
* 'use server';
|
|
418
|
+
* import { authServer } from '@/lib/auth/server';
|
|
419
|
+
* import { redirect } from 'next/navigation';
|
|
420
|
+
*
|
|
421
|
+
* export async function signIn(formData: FormData) {
|
|
422
|
+
* const { error } = await authServer.signIn.email({
|
|
423
|
+
* email: formData.get('email') as string,
|
|
424
|
+
* password: formData.get('password') as string,
|
|
425
|
+
* });
|
|
426
|
+
* if (error) return { error: error.message };
|
|
427
|
+
* redirect('/dashboard');
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
declare function createAuthServer(): NeonAuthServer;
|
|
432
|
+
//#endregion
|
|
433
|
+
export { authApiHandler, createAuthServer, neonAuth, neonAuthMiddleware };
|