@neondatabase/auth 0.1.0-beta.1 → 0.1.0-beta.11

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.
Files changed (39) hide show
  1. package/README.md +8 -6
  2. package/dist/{adapter-core-C12KoaiU.d.mts → adapter-core-Bw9mn_AS.d.mts} +95 -508
  3. package/dist/{adapter-core-BDOw-gBC.mjs → adapter-core-C_NEMs0b.mjs} +2 -4
  4. package/dist/{better-auth-react-adapter-FnBHa2nr.mjs → better-auth-react-adapter-BbM3jLLv.mjs} +1 -1
  5. package/dist/{better-auth-react-adapter-BXL48HIU.d.mts → better-auth-react-adapter-JoscqoDc.d.mts} +88 -88
  6. package/dist/better-auth-types-CE4hLv9E.d.mts +9 -0
  7. package/dist/chunk-5DLVHPZS-Bxj7snpZ-DoVNlsyk.mjs +533 -0
  8. package/dist/index.d.mts +3 -3
  9. package/dist/index.mjs +1 -1
  10. package/dist/{neon-auth-C9XTFffv.mjs → neon-auth-DdlToh7_.mjs} +1 -1
  11. package/dist/next/index.d.mts +80 -198
  12. package/dist/next/index.mjs +199 -60
  13. package/dist/react/adapters/index.d.mts +3 -3
  14. package/dist/react/adapters/index.mjs +1 -1
  15. package/dist/react/index.d.mts +4 -4
  16. package/dist/react/index.mjs +4 -92
  17. package/dist/react/ui/index.d.mts +1 -1
  18. package/dist/react/ui/index.mjs +3 -91
  19. package/dist/react/ui/server.mjs +1 -1
  20. package/dist/{supabase-adapter-ggmqWgPe.mjs → supabase-adapter-CAqbpOC7.mjs} +45 -123
  21. package/dist/{supabase-adapter-crabDnl2.d.mts → supabase-adapter-Clxlqg1x.d.mts} +1 -2
  22. package/dist/types/index.d.mts +8 -0
  23. package/dist/types/index.mjs +3 -0
  24. package/dist/ui/.safelist.html +3 -0
  25. package/dist/ui/css.css +1 -1
  26. package/dist/ui/tailwind.css +2 -2
  27. package/dist/ui/theme.css +125 -49
  28. package/dist/ui-aMoA-9nq.mjs +9449 -0
  29. package/dist/vanilla/adapters/index.d.mts +3 -3
  30. package/dist/vanilla/adapters/index.mjs +1 -1
  31. package/dist/vanilla/index.d.mts +3 -3
  32. package/dist/vanilla/index.mjs +1 -1
  33. package/package.json +7 -3
  34. package/dist/ui-CNFBSekF.mjs +0 -401
  35. /package/dist/{adapters-CivF9wql.mjs → adapters-D0mxG3F-.mjs} +0 -0
  36. /package/dist/{adapters-Dkx0zoMR.mjs → adapters-Df6Dd3KK.mjs} +0 -0
  37. /package/dist/{index-DuDD6cIY.d.mts → index-BXlAjlSt.d.mts} +0 -0
  38. /package/dist/{index-C-svZlpj.d.mts → index-ClXLQ1fw.d.mts} +0 -0
  39. /package/dist/{index-UW23fDSn.d.mts → index-DCQ5Y2ED.d.mts} +0 -0
@@ -1,3 +1,4 @@
1
+ import { n as BetterAuthSession, r as BetterAuthUser } from "../better-auth-types-CE4hLv9E.mjs";
1
2
  import * as better_auth_client0 from "better-auth/client";
2
3
  import * as better_auth_client_plugins0 from "better-auth/client/plugins";
3
4
  import * as jose0 from "jose";
@@ -10,7 +11,26 @@ import * as nanostores0 from "nanostores";
10
11
  type Params = {
11
12
  path: string[];
12
13
  };
13
- declare const toNextJsHandler: (baseUrl: string) => {
14
+ /**
15
+ *
16
+ * An API route handler to handle the auth requests from the client and proxy them to the Neon Auth.
17
+ *
18
+ * @returns A Next.js API handler functions those can be used in a Next.js route.
19
+ *
20
+ * @example
21
+ *
22
+ * Mount the `authApiHandler` to an API route. Create a route file inside `/api/auth/[...all]/route.ts` directory.
23
+ * And add the following code:
24
+ *
25
+ * ```ts
26
+ *
27
+ * import { authApiHandler } from '@neondatabase/auth/next';
28
+ *
29
+ * export const { GET, POST } = authApiHandler();
30
+ * ```
31
+ *
32
+ */
33
+ declare function authApiHandler(): {
14
34
  GET: (request: Request, {
15
35
  params
16
36
  }: {
@@ -41,23 +61,50 @@ declare const toNextJsHandler: (baseUrl: string) => {
41
61
  //#region src/next/middleware/index.d.ts
42
62
  type NeonAuthMiddlewareOptions = {
43
63
  loginUrl?: string;
44
- /**
45
- * The Neon Auth base URL
46
- * Defaults to `process.env.NEON_AUTH_BASE_URL`
47
- *
48
- * If not provided, and if not in the environment, the middleware will throw an error.
49
- *
50
- * @throws {Error} If the authURL is not provided and not in the environment.
51
- */
52
- authBaseUrl?: string;
53
64
  };
54
- declare const neonAuthMiddleware: ({
55
- loginUrl,
56
- authBaseUrl
57
- }: NeonAuthMiddlewareOptions) => (request: NextRequest) => Promise<NextResponse<unknown>>;
65
+ /**
66
+ * A Next.js middleware to protect routes from unauthenticated requests and refresh the session if required.
67
+ *
68
+ * @param loginUrl - The URL to redirect to when the user is not authenticated.
69
+ * @returns A middleware function that can be used in the Next.js app.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { neonAuthMiddleware } from "@neondatabase/auth/next"
74
+ *
75
+ * export default neonAuthMiddleware({
76
+ * loginUrl: '/auth/sign-in',
77
+ * });
78
+ * ```
79
+ */
80
+ declare function neonAuthMiddleware({
81
+ loginUrl
82
+ }: NeonAuthMiddlewareOptions): (request: NextRequest) => Promise<NextResponse<unknown>>;
83
+ //#endregion
84
+ //#region src/next/auth/session.d.ts
85
+ type SessionData = {
86
+ session: BetterAuthSession;
87
+ user: BetterAuthUser;
88
+ } | {
89
+ session: null;
90
+ user: null;
91
+ };
92
+ /**
93
+ * 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.
94
+ *
95
+ * @returns - `{ session: Session, user: User }` | `{ session: null, user: null}`.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { neonAuth } from "@neondatabase/auth/next"
100
+ *
101
+ * const { session, user } = await neonAuth()
102
+ * ```
103
+ */
104
+ declare const neonAuth: () => Promise<SessionData>;
58
105
  //#endregion
59
106
  //#region src/next/index.d.ts
60
- declare const createAuthClient: () => {
107
+ declare function createAuthClient(): {
61
108
  useActiveOrganization: () => {
62
109
  data: better_auth0.Prettify<{
63
110
  id: string;
@@ -351,15 +398,7 @@ declare const createAuthClient: () => {
351
398
  ipAddress?: string | null | undefined;
352
399
  userAgent?: string | null | undefined;
353
400
  };
354
- user: {
355
- id: string;
356
- createdAt: Date;
357
- updatedAt: Date;
358
- email: string;
359
- emailVerified: boolean;
360
- name: string;
361
- image?: string | null | undefined;
362
- };
401
+ user: better_auth_client_plugins0.UserWithRole;
363
402
  }, {
364
403
  code?: string | undefined;
365
404
  message?: string | undefined;
@@ -990,7 +1029,7 @@ declare const createAuthClient: () => {
990
1029
  email?: string | undefined;
991
1030
  } | undefined;
992
1031
  fetchOptions?: FetchOptions | undefined;
993
- }> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1032
+ }> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<(Omit<{
994
1033
  id: string;
995
1034
  organizationId: string;
996
1035
  email: string;
@@ -999,7 +1038,18 @@ declare const createAuthClient: () => {
999
1038
  inviterId: string;
1000
1039
  expiresAt: Date;
1001
1040
  createdAt: Date;
1002
- }[], {
1041
+ } & {
1042
+ organization: {
1043
+ id: string;
1044
+ name: string;
1045
+ slug: string;
1046
+ createdAt: Date;
1047
+ logo?: string | null | undefined | undefined;
1048
+ metadata?: any;
1049
+ };
1050
+ }, "organization"> & {
1051
+ organizationName: string;
1052
+ })[], {
1003
1053
  code?: string | undefined;
1004
1054
  message?: string | undefined;
1005
1055
  }, FetchOptions["throw"] extends true ? true : false>>;
@@ -1283,156 +1333,6 @@ declare const createAuthClient: () => {
1283
1333
  message?: string | undefined;
1284
1334
  }, FetchOptions["throw"] extends true ? true : false>>;
1285
1335
  };
1286
- } & {
1287
- signIn: {
1288
- phoneNumber: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
1289
- phoneNumber: string;
1290
- password: string;
1291
- rememberMe?: boolean | undefined;
1292
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1293
- phoneNumber: string;
1294
- password: string;
1295
- rememberMe?: boolean | undefined;
1296
- } & {
1297
- fetchOptions?: FetchOptions | undefined;
1298
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1299
- token: string;
1300
- user: better_auth_client_plugins0.UserWithPhoneNumber;
1301
- }, {
1302
- code?: string | undefined;
1303
- message?: string | undefined;
1304
- }, FetchOptions["throw"] extends true ? true : false>>;
1305
- };
1306
- } & {
1307
- phoneNumber: {
1308
- sendOtp: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
1309
- phoneNumber: string;
1310
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1311
- phoneNumber: string;
1312
- } & {
1313
- fetchOptions?: FetchOptions | undefined;
1314
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1315
- message: string;
1316
- }, {
1317
- code?: string | undefined;
1318
- message?: string | undefined;
1319
- }, FetchOptions["throw"] extends true ? true : false>>;
1320
- };
1321
- } & {
1322
- phoneNumber: {
1323
- verify: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
1324
- phoneNumber: string;
1325
- code: string;
1326
- disableSession?: boolean | undefined;
1327
- updatePhoneNumber?: boolean | undefined;
1328
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1329
- phoneNumber: string;
1330
- code: string;
1331
- disableSession?: boolean | undefined;
1332
- updatePhoneNumber?: boolean | undefined;
1333
- } & {
1334
- fetchOptions?: FetchOptions | undefined;
1335
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<NonNullable<{
1336
- status: boolean;
1337
- token: string;
1338
- user: better_auth_client_plugins0.UserWithPhoneNumber;
1339
- } | {
1340
- status: boolean;
1341
- token: null;
1342
- user: better_auth_client_plugins0.UserWithPhoneNumber;
1343
- }>, {
1344
- code?: string | undefined;
1345
- message?: string | undefined;
1346
- }, FetchOptions["throw"] extends true ? true : false>>;
1347
- };
1348
- } & {
1349
- phoneNumber: {
1350
- requestPasswordReset: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
1351
- phoneNumber: string;
1352
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1353
- phoneNumber: string;
1354
- } & {
1355
- fetchOptions?: FetchOptions | undefined;
1356
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1357
- status: boolean;
1358
- }, {
1359
- code?: string | undefined;
1360
- message?: string | undefined;
1361
- }, FetchOptions["throw"] extends true ? true : false>>;
1362
- };
1363
- } & {
1364
- phoneNumber: {
1365
- resetPassword: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
1366
- otp: string;
1367
- phoneNumber: string;
1368
- newPassword: string;
1369
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1370
- otp: string;
1371
- phoneNumber: string;
1372
- newPassword: string;
1373
- } & {
1374
- fetchOptions?: FetchOptions | undefined;
1375
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1376
- status: boolean;
1377
- }, {
1378
- code?: string | undefined;
1379
- message?: string | undefined;
1380
- }, FetchOptions["throw"] extends true ? true : false>>;
1381
- };
1382
- } & {
1383
- signIn: {
1384
- magicLink: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
1385
- email: string;
1386
- name?: string | undefined;
1387
- callbackURL?: string | undefined;
1388
- newUserCallbackURL?: string | undefined;
1389
- errorCallbackURL?: string | undefined;
1390
- }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1391
- email: string;
1392
- name?: string | undefined;
1393
- callbackURL?: string | undefined;
1394
- newUserCallbackURL?: string | undefined;
1395
- errorCallbackURL?: string | undefined;
1396
- } & {
1397
- fetchOptions?: FetchOptions | undefined;
1398
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1399
- status: boolean;
1400
- }, {
1401
- code?: string | undefined;
1402
- message?: string | undefined;
1403
- }, FetchOptions["throw"] extends true ? true : false>>;
1404
- };
1405
- } & {
1406
- magicLink: {
1407
- verify: <FetchOptions extends better_auth0.ClientFetchOption<never, Partial<{
1408
- token: string;
1409
- callbackURL?: string | undefined;
1410
- errorCallbackURL?: string | undefined;
1411
- newUserCallbackURL?: string | undefined;
1412
- }> & Record<string, any>, Record<string, any> | undefined>>(data_0: better_auth0.Prettify<{
1413
- query: {
1414
- token: string;
1415
- callbackURL?: string | undefined;
1416
- errorCallbackURL?: string | undefined;
1417
- newUserCallbackURL?: string | undefined;
1418
- };
1419
- fetchOptions?: FetchOptions | undefined;
1420
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1421
- token: string;
1422
- user: {
1423
- id: string;
1424
- email: string;
1425
- emailVerified: boolean;
1426
- name: string;
1427
- image: string | null | undefined;
1428
- createdAt: Date;
1429
- updatedAt: Date;
1430
- };
1431
- }, {
1432
- code?: string | undefined;
1433
- message?: string | undefined;
1434
- }, FetchOptions["throw"] extends true ? true : false>>;
1435
- };
1436
1336
  } & {
1437
1337
  signIn: {
1438
1338
  social: <FetchOptions extends better_auth0.ClientFetchOption<Partial<{
@@ -1518,9 +1418,7 @@ declare const createAuthClient: () => {
1518
1418
  image?: string | undefined;
1519
1419
  callbackURL?: string | undefined;
1520
1420
  fetchOptions?: FetchOptions | undefined;
1521
- } & {} & {} & {} & {} & {} & {
1522
- phoneNumber?: string | null | undefined;
1523
- }>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<NonNullable<{
1421
+ } & {} & {} & {} & {}>, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<NonNullable<{
1524
1422
  token: null;
1525
1423
  user: {
1526
1424
  id: string;
@@ -1676,9 +1574,7 @@ declare const createAuthClient: () => {
1676
1574
  image?: (string | null) | undefined;
1677
1575
  name?: string | undefined;
1678
1576
  fetchOptions?: FetchOptions | undefined;
1679
- } & Partial<{} & {} & {} & {} & {} & {
1680
- phoneNumber?: string | null | undefined;
1681
- }>> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1577
+ } & Partial<{} & {} & {} & {}>> | undefined, data_1?: FetchOptions | undefined) => Promise<_better_fetch_fetch0.BetterFetchResponse<{
1682
1578
  status: boolean;
1683
1579
  }, {
1684
1580
  code?: string | undefined;
@@ -1957,8 +1853,6 @@ declare const createAuthClient: () => {
1957
1853
  banReason?: string | null | undefined;
1958
1854
  banExpires?: Date | null | undefined;
1959
1855
  isAnonymous: boolean | null | undefined;
1960
- phoneNumber?: string | null | undefined;
1961
- phoneNumberVerified?: boolean | null | undefined;
1962
1856
  };
1963
1857
  session: {
1964
1858
  id: string;
@@ -2118,8 +2012,6 @@ declare const createAuthClient: () => {
2118
2012
  banReason?: string | null | undefined;
2119
2013
  banExpires?: Date | null | undefined;
2120
2014
  isAnonymous: boolean | null | undefined;
2121
- phoneNumber?: string | null | undefined;
2122
- phoneNumberVerified?: boolean | null | undefined;
2123
2015
  };
2124
2016
  session: {
2125
2017
  id: string;
@@ -2156,8 +2048,6 @@ declare const createAuthClient: () => {
2156
2048
  banReason?: string | null | undefined;
2157
2049
  banExpires?: Date | null | undefined;
2158
2050
  isAnonymous: boolean | null | undefined;
2159
- phoneNumber?: string | null | undefined;
2160
- phoneNumberVerified?: boolean | null | undefined;
2161
2051
  };
2162
2052
  session: {
2163
2053
  id: string;
@@ -2264,6 +2154,7 @@ declare const createAuthClient: () => {
2264
2154
  readonly YOU_ARE_NOT_ALLOWED_TO_UPDATE_USERS: "You are not allowed to update users";
2265
2155
  readonly YOU_CANNOT_REMOVE_YOURSELF: "You cannot remove yourself";
2266
2156
  readonly YOU_ARE_NOT_ALLOWED_TO_SET_NON_EXISTENT_VALUE: "You are not allowed to set a non-existent role value";
2157
+ readonly YOU_CANNOT_IMPERSONATE_ADMINS: "You cannot impersonate admins";
2267
2158
  readonly YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION: "You are not allowed to create a new organization";
2268
2159
  readonly YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS: "You have reached the maximum number of organizations";
2269
2160
  readonly ORGANIZATION_ALREADY_EXISTS: "Organization already exists";
@@ -2326,15 +2217,6 @@ declare const createAuthClient: () => {
2326
2217
  readonly INVALID_EMAIL_FORMAT: "Email was not generated in a valid format";
2327
2218
  readonly COULD_NOT_CREATE_SESSION: "Could not create session";
2328
2219
  readonly ANONYMOUS_USERS_CANNOT_SIGN_IN_AGAIN_ANONYMOUSLY: "Anonymous users cannot sign in again anonymously";
2329
- readonly INVALID_PHONE_NUMBER: "Invalid phone number";
2330
- readonly PHONE_NUMBER_EXIST: "Phone number already exists";
2331
- readonly PHONE_NUMBER_NOT_EXIST: "phone number isn't registered";
2332
- readonly INVALID_PHONE_NUMBER_OR_PASSWORD: "Invalid phone number or password";
2333
- readonly UNEXPECTED_ERROR: "Unexpected error";
2334
- readonly OTP_NOT_FOUND: "OTP not found";
2335
- readonly PHONE_NUMBER_NOT_VERIFIED: "Phone number not verified";
2336
- readonly PHONE_NUMBER_CANNOT_BE_UPDATED: "Phone number cannot be updated";
2337
- readonly SEND_OTP_NOT_IMPLEMENTED: "sendOTP not implemented";
2338
2220
  readonly USER_NOT_FOUND: "User not found";
2339
2221
  readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
2340
2222
  readonly FAILED_TO_UPDATE_USER: "Failed to update user";
@@ -2360,4 +2242,4 @@ declare const createAuthClient: () => {
2360
2242
  };
2361
2243
  };
2362
2244
  //#endregion
2363
- export { createAuthClient, neonAuthMiddleware, toNextJsHandler };
2245
+ export { authApiHandler, createAuthClient, neonAuth, neonAuthMiddleware };