naystack 1.7.0 → 1.7.3

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 (92) hide show
  1. package/README.md +45 -28
  2. package/dist/auth/client.cjs.js +230 -0
  3. package/dist/auth/client.d.mts +3 -0
  4. package/dist/auth/client.d.ts +3 -0
  5. package/dist/auth/client.esm.js +190 -0
  6. package/dist/auth/email/client.cjs.js +6 -2
  7. package/dist/auth/email/client.d.mts +34 -12
  8. package/dist/auth/email/client.d.ts +34 -12
  9. package/dist/auth/email/client.esm.js +6 -2
  10. package/dist/auth/email/index.cjs.js +11 -6
  11. package/dist/auth/email/index.d.mts +8 -7
  12. package/dist/auth/email/index.d.ts +8 -7
  13. package/dist/auth/email/index.esm.js +9 -5
  14. package/dist/auth/email/{server.cjs.js → next.cjs.js} +16 -7
  15. package/dist/auth/email/next.d.mts +7 -0
  16. package/dist/auth/email/next.d.ts +7 -0
  17. package/dist/auth/email/{server.esm.js → next.esm.js} +8 -4
  18. package/dist/auth/email/routes/delete.d.mts +3 -3
  19. package/dist/auth/email/routes/delete.d.ts +3 -3
  20. package/dist/auth/email/routes/get.d.mts +3 -3
  21. package/dist/auth/email/routes/get.d.ts +3 -3
  22. package/dist/auth/email/routes/post.d.mts +3 -3
  23. package/dist/auth/email/routes/post.d.ts +3 -3
  24. package/dist/auth/email/routes/put.d.mts +3 -3
  25. package/dist/auth/email/routes/put.d.ts +3 -3
  26. package/dist/auth/email/token.cjs.js +3 -3
  27. package/dist/auth/email/token.d.mts +2 -2
  28. package/dist/auth/email/token.d.ts +2 -2
  29. package/dist/auth/email/token.esm.js +3 -3
  30. package/dist/auth/email/types.d.mts +5 -4
  31. package/dist/auth/email/types.d.ts +5 -4
  32. package/dist/auth/email/utils.d.mts +3 -3
  33. package/dist/auth/email/utils.d.ts +3 -3
  34. package/dist/auth/google/get.d.mts +3 -3
  35. package/dist/auth/google/get.d.ts +3 -3
  36. package/dist/auth/google/index.cjs.js +3 -3
  37. package/dist/auth/google/index.d.mts +7 -7
  38. package/dist/auth/google/index.d.ts +7 -7
  39. package/dist/auth/google/index.esm.js +2 -2
  40. package/dist/auth/index.cjs.js +25 -25
  41. package/dist/auth/index.d.mts +5 -4
  42. package/dist/auth/index.d.ts +5 -4
  43. package/dist/auth/index.esm.js +12 -12
  44. package/dist/auth/instagram/index.cjs.js +6 -6
  45. package/dist/auth/instagram/index.d.mts +8 -9
  46. package/dist/auth/instagram/index.d.ts +8 -9
  47. package/dist/auth/instagram/index.esm.js +5 -5
  48. package/dist/auth/instagram/route.cjs.js +3 -3
  49. package/dist/auth/instagram/route.d.mts +3 -3
  50. package/dist/auth/instagram/route.d.ts +3 -3
  51. package/dist/auth/instagram/route.esm.js +3 -3
  52. package/dist/file/client.cjs.js +1 -1
  53. package/dist/file/client.d.mts +7 -7
  54. package/dist/file/client.d.ts +7 -7
  55. package/dist/file/client.esm.js +1 -1
  56. package/dist/graphql/client.cjs.js +1 -1
  57. package/dist/graphql/client.d.mts +5 -5
  58. package/dist/graphql/client.d.ts +5 -5
  59. package/dist/graphql/client.esm.js +1 -1
  60. package/dist/graphql/index.cjs.js +94 -6
  61. package/dist/graphql/index.d.mts +7 -2
  62. package/dist/graphql/index.d.ts +7 -2
  63. package/dist/graphql/index.esm.js +97 -4
  64. package/dist/graphql/init.cjs.js +3 -3
  65. package/dist/graphql/init.d.mts +4 -4
  66. package/dist/graphql/init.d.ts +4 -4
  67. package/dist/graphql/init.esm.js +2 -2
  68. package/dist/graphql/utils.cjs.js +17 -3
  69. package/dist/graphql/utils.d.mts +16 -16
  70. package/dist/graphql/utils.d.ts +16 -16
  71. package/dist/graphql/utils.esm.js +16 -2
  72. package/dist/index.d.mts +2 -2
  73. package/dist/index.d.ts +2 -2
  74. package/dist/socials/instagram/webhook.d.mts +2 -2
  75. package/dist/socials/instagram/webhook.d.ts +2 -2
  76. package/dist/{client → utils/client}/hooks.cjs.js +1 -1
  77. package/dist/{client → utils/client}/hooks.esm.js +1 -1
  78. package/dist/{client → utils/client}/index.cjs.js +3 -3
  79. package/dist/{client → utils/client}/index.esm.js +2 -2
  80. package/dist/{client → utils/client}/seo.cjs.js +2 -2
  81. package/dist/{client → utils/client}/seo.esm.js +1 -1
  82. package/dist/utils/route.d.mts +20 -0
  83. package/dist/utils/route.d.ts +20 -0
  84. package/package.json +17 -32
  85. package/dist/auth/email/server.d.mts +0 -5
  86. package/dist/auth/email/server.d.ts +0 -5
  87. /package/dist/{client → utils/client}/hooks.d.mts +0 -0
  88. /package/dist/{client → utils/client}/hooks.d.ts +0 -0
  89. /package/dist/{client → utils/client}/index.d.mts +0 -0
  90. /package/dist/{client → utils/client}/index.d.ts +0 -0
  91. /package/dist/{client → utils/client}/seo.d.mts +0 -0
  92. /package/dist/{client → utils/client}/seo.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- import React__default, { Dispatch, SetStateAction } from 'react';
1
+ import React__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
2
2
 
3
3
  /**
4
4
  * React context holding the current access token and setter; used by useToken/useSetToken and auth hooks.
@@ -8,6 +8,11 @@ declare const TokenContext: React__default.Context<{
8
8
  token: string | null | undefined;
9
9
  setToken: Dispatch<SetStateAction<string | null | undefined>>;
10
10
  }>;
11
+ type AuthWrapperProps = PropsWithChildren<{
12
+ onTokenUpdate?: (token: string | null) => void;
13
+ getRefreshToken?: () => Promise<string | null>;
14
+ skipInitialFetch?: boolean;
15
+ }>;
11
16
  /**
12
17
  * Provider that fetches the current access token from your auth endpoint and exposes it via TokenContext.
13
18
  * Wrap your app (or the part that needs auth) so that `useToken()`, `useLogin()`, `useSignUp()`, `useLogout()` work.
@@ -16,12 +21,13 @@ declare const TokenContext: React__default.Context<{
16
21
  * Must be placed **above** `ApolloWrapper` in the component tree (since `ApolloWrapper` needs the token).
17
22
  *
18
23
  * @param children - React children (e.g. your app or a layout).
24
+ * @param onTokenUpdate - Optional callback fired whenever the token changes (after initial load). Receives `token` (string) or `null` on logout.
19
25
  * @returns TokenContext.Provider wrapping children.
20
26
  *
21
27
  * @example
22
28
  * ```tsx
23
29
  * // app/layout.tsx
24
- * import { AuthWrapper } from "naystack/auth/email/client";
30
+ * import { AuthWrapper } from "naystack/auth/client";
25
31
  * import { ApolloWrapper } from "naystack/graphql/client";
26
32
  *
27
33
  * export default function RootLayout({ children }: { children: React.ReactNode }) {
@@ -39,11 +45,27 @@ declare const TokenContext: React__default.Context<{
39
45
  *
40
46
  * @category Auth
41
47
  */
42
- declare const AuthWrapper: ({ children, onTokenUpdate, }: {
43
- children: React__default.ReactNode;
44
- onTokenUpdate?: (token: string | null) => void;
45
- }) => React__default.JSX.Element;
46
- declare function useAuthFetch(getRefreshToken?: () => Promise<string | null>): void;
48
+ declare const AuthWrapper: ({ children, onTokenUpdate, getRefreshToken, skipInitialFetch }: AuthWrapperProps) => React__default.JSX.Element;
49
+ /**
50
+ * Fetches the access token on mount by calling the auth endpoint. Stores the result in TokenContext.
51
+ * Used internally by auth setup; prefer `AuthWrapper` for typical usage.
52
+ *
53
+ * @param getRefreshToken - Optional async function that returns a refresh token string (e.g. from cookies or storage). If omitted, the request relies on httpOnly cookies via `credentials: "include"`.
54
+ *
55
+ * @category Auth
56
+ */
57
+ declare function useAuthFetch({ getRefreshToken, skip }: {
58
+ getRefreshToken?: () => Promise<string | null>;
59
+ skip?: boolean;
60
+ }): void;
61
+ /**
62
+ * Component that applies a server-provided access token into TokenContext on mount.
63
+ * Useful for hydrating auth state from server-side rendering.
64
+ *
65
+ * @param data - The access token string to set. If falsy, no update occurs.
66
+ *
67
+ * @category Auth
68
+ */
47
69
  declare function AuthApply({ data }: {
48
70
  data?: string | null;
49
71
  }): null;
@@ -56,7 +78,7 @@ declare function AuthApply({ data }: {
56
78
  *
57
79
  * @example
58
80
  * ```tsx
59
- * import { useToken } from "naystack/auth/email/client";
81
+ * import { useToken } from "naystack/auth/client";
60
82
  *
61
83
  * function Navbar() {
62
84
  * const token = useToken();
@@ -95,7 +117,7 @@ declare function useSetToken(): React__default.Dispatch<React__default.SetStateA
95
117
  *
96
118
  * @example
97
119
  * ```tsx
98
- * import { useSignUp } from "naystack/auth/email/client";
120
+ * import { useSignUp } from "naystack/auth/client";
99
121
  *
100
122
  * function SignUpForm() {
101
123
  * const signUp = useSignUp();
@@ -122,7 +144,7 @@ declare function useSignUp(): (data: object) => Promise<string | null>;
122
144
  *
123
145
  * @example
124
146
  * ```tsx
125
- * import { useLogin } from "naystack/auth/email/client";
147
+ * import { useLogin } from "naystack/auth/client";
126
148
  *
127
149
  * function LoginForm() {
128
150
  * const login = useLogin();
@@ -149,7 +171,7 @@ declare function useLogin(): (data: object) => Promise<string | null>;
149
171
  *
150
172
  * @example
151
173
  * ```tsx
152
- * import { useLogout } from "naystack/auth/email/client";
174
+ * import { useLogout } from "naystack/auth/client";
153
175
  *
154
176
  * function SettingsPage() {
155
177
  * const logout = useLogout();
@@ -167,4 +189,4 @@ declare function useLogin(): (data: object) => Promise<string | null>;
167
189
  */
168
190
  declare function useLogout(): (data?: object) => Promise<void>;
169
191
 
170
- export { AuthApply, AuthWrapper, TokenContext, useAuthFetch, useLogin, useLogout, useSetToken, useSignUp, useToken };
192
+ export { AuthApply, AuthWrapper, type AuthWrapperProps, TokenContext, useAuthFetch, useLogin, useLogout, useSetToken, useSignUp, useToken };
@@ -1,4 +1,4 @@
1
- import React__default, { Dispatch, SetStateAction } from 'react';
1
+ import React__default, { Dispatch, SetStateAction, PropsWithChildren } from 'react';
2
2
 
3
3
  /**
4
4
  * React context holding the current access token and setter; used by useToken/useSetToken and auth hooks.
@@ -8,6 +8,11 @@ declare const TokenContext: React__default.Context<{
8
8
  token: string | null | undefined;
9
9
  setToken: Dispatch<SetStateAction<string | null | undefined>>;
10
10
  }>;
11
+ type AuthWrapperProps = PropsWithChildren<{
12
+ onTokenUpdate?: (token: string | null) => void;
13
+ getRefreshToken?: () => Promise<string | null>;
14
+ skipInitialFetch?: boolean;
15
+ }>;
11
16
  /**
12
17
  * Provider that fetches the current access token from your auth endpoint and exposes it via TokenContext.
13
18
  * Wrap your app (or the part that needs auth) so that `useToken()`, `useLogin()`, `useSignUp()`, `useLogout()` work.
@@ -16,12 +21,13 @@ declare const TokenContext: React__default.Context<{
16
21
  * Must be placed **above** `ApolloWrapper` in the component tree (since `ApolloWrapper` needs the token).
17
22
  *
18
23
  * @param children - React children (e.g. your app or a layout).
24
+ * @param onTokenUpdate - Optional callback fired whenever the token changes (after initial load). Receives `token` (string) or `null` on logout.
19
25
  * @returns TokenContext.Provider wrapping children.
20
26
  *
21
27
  * @example
22
28
  * ```tsx
23
29
  * // app/layout.tsx
24
- * import { AuthWrapper } from "naystack/auth/email/client";
30
+ * import { AuthWrapper } from "naystack/auth/client";
25
31
  * import { ApolloWrapper } from "naystack/graphql/client";
26
32
  *
27
33
  * export default function RootLayout({ children }: { children: React.ReactNode }) {
@@ -39,11 +45,27 @@ declare const TokenContext: React__default.Context<{
39
45
  *
40
46
  * @category Auth
41
47
  */
42
- declare const AuthWrapper: ({ children, onTokenUpdate, }: {
43
- children: React__default.ReactNode;
44
- onTokenUpdate?: (token: string | null) => void;
45
- }) => React__default.JSX.Element;
46
- declare function useAuthFetch(getRefreshToken?: () => Promise<string | null>): void;
48
+ declare const AuthWrapper: ({ children, onTokenUpdate, getRefreshToken, skipInitialFetch }: AuthWrapperProps) => React__default.JSX.Element;
49
+ /**
50
+ * Fetches the access token on mount by calling the auth endpoint. Stores the result in TokenContext.
51
+ * Used internally by auth setup; prefer `AuthWrapper` for typical usage.
52
+ *
53
+ * @param getRefreshToken - Optional async function that returns a refresh token string (e.g. from cookies or storage). If omitted, the request relies on httpOnly cookies via `credentials: "include"`.
54
+ *
55
+ * @category Auth
56
+ */
57
+ declare function useAuthFetch({ getRefreshToken, skip }: {
58
+ getRefreshToken?: () => Promise<string | null>;
59
+ skip?: boolean;
60
+ }): void;
61
+ /**
62
+ * Component that applies a server-provided access token into TokenContext on mount.
63
+ * Useful for hydrating auth state from server-side rendering.
64
+ *
65
+ * @param data - The access token string to set. If falsy, no update occurs.
66
+ *
67
+ * @category Auth
68
+ */
47
69
  declare function AuthApply({ data }: {
48
70
  data?: string | null;
49
71
  }): null;
@@ -56,7 +78,7 @@ declare function AuthApply({ data }: {
56
78
  *
57
79
  * @example
58
80
  * ```tsx
59
- * import { useToken } from "naystack/auth/email/client";
81
+ * import { useToken } from "naystack/auth/client";
60
82
  *
61
83
  * function Navbar() {
62
84
  * const token = useToken();
@@ -95,7 +117,7 @@ declare function useSetToken(): React__default.Dispatch<React__default.SetStateA
95
117
  *
96
118
  * @example
97
119
  * ```tsx
98
- * import { useSignUp } from "naystack/auth/email/client";
120
+ * import { useSignUp } from "naystack/auth/client";
99
121
  *
100
122
  * function SignUpForm() {
101
123
  * const signUp = useSignUp();
@@ -122,7 +144,7 @@ declare function useSignUp(): (data: object) => Promise<string | null>;
122
144
  *
123
145
  * @example
124
146
  * ```tsx
125
- * import { useLogin } from "naystack/auth/email/client";
147
+ * import { useLogin } from "naystack/auth/client";
126
148
  *
127
149
  * function LoginForm() {
128
150
  * const login = useLogin();
@@ -149,7 +171,7 @@ declare function useLogin(): (data: object) => Promise<string | null>;
149
171
  *
150
172
  * @example
151
173
  * ```tsx
152
- * import { useLogout } from "naystack/auth/email/client";
174
+ * import { useLogout } from "naystack/auth/client";
153
175
  *
154
176
  * function SettingsPage() {
155
177
  * const logout = useLogout();
@@ -167,4 +189,4 @@ declare function useLogin(): (data: object) => Promise<string | null>;
167
189
  */
168
190
  declare function useLogout(): (data?: object) => Promise<void>;
169
191
 
170
- export { AuthApply, AuthWrapper, TokenContext, useAuthFetch, useLogin, useLogout, useSetToken, useSignUp, useToken };
192
+ export { AuthApply, AuthWrapper, type AuthWrapperProps, TokenContext, useAuthFetch, useLogin, useLogout, useSetToken, useSignUp, useToken };
@@ -69,9 +69,12 @@ var TokenContext = createContext({
69
69
  });
70
70
  var AuthWrapper = ({
71
71
  children,
72
- onTokenUpdate
72
+ onTokenUpdate,
73
+ getRefreshToken,
74
+ skipInitialFetch
73
75
  }) => {
74
76
  const [token, setToken] = useState();
77
+ useAuthFetch({ getRefreshToken, skip: skipInitialFetch });
75
78
  useEffect(() => {
76
79
  if (onTokenUpdate && token !== void 0) {
77
80
  onTokenUpdate(token);
@@ -79,7 +82,7 @@ var AuthWrapper = ({
79
82
  }, [token]);
80
83
  return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
81
84
  };
82
- function useAuthFetch(getRefreshToken) {
85
+ function useAuthFetch({ getRefreshToken, skip }) {
83
86
  const setToken = useSetToken();
84
87
  const fetchToken = async () => {
85
88
  const token = getRefreshToken ? await getRefreshToken() : null;
@@ -91,6 +94,7 @@ function useAuthFetch(getRefreshToken) {
91
94
  }).then((res) => res.json()).then((data) => setToken(data.accessToken || null));
92
95
  };
93
96
  useEffect(() => {
97
+ if (skip) return;
94
98
  fetchToken();
95
99
  }, []);
96
100
  }
@@ -31,9 +31,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var email_exports = {};
32
32
  __export(email_exports, {
33
33
  AuthFetch: () => AuthFetch,
34
+ AuthWrapper: () => AuthWrapper,
34
35
  checkAuthStatus: () => checkAuthStatus,
35
36
  getContext: () => getContext,
36
- getEmailAuthRoutes: () => getEmailAuthRoutes
37
+ setupEmailAuth: () => setupEmailAuth
37
38
  });
38
39
  module.exports = __toCommonJS(email_exports);
39
40
  var import_server5 = require("next/server");
@@ -343,8 +344,8 @@ var getPutRoute = (options) => async (req) => {
343
344
  return handleError(403, "Invalid password", options.onError);
344
345
  };
345
346
 
346
- // src/auth/email/server.tsx
347
- var import_client2 = require("naystack/auth/email/client");
347
+ // src/auth/email/next.tsx
348
+ var import_client2 = require("naystack/auth/client");
348
349
  var import_headers3 = require("next/headers");
349
350
  var import_react3 = __toESM(require("react"));
350
351
 
@@ -378,7 +379,7 @@ var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloCli
378
379
  });
379
380
  });
380
381
 
381
- // src/auth/email/server.tsx
382
+ // src/auth/email/next.tsx
382
383
  function AuthFetch() {
383
384
  return /* @__PURE__ */ import_react3.default.createElement(
384
385
  Injector,
@@ -398,9 +399,12 @@ function AuthFetch() {
398
399
  }
399
400
  );
400
401
  }
402
+ function AuthWrapper({ children, getRefreshToken, onTokenUpdate, skipInitialFetch }) {
403
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, /* @__PURE__ */ import_react3.default.createElement(import_client2.AuthWrapper, { skipInitialFetch: true, getRefreshToken, onTokenUpdate }, !skipInitialFetch && /* @__PURE__ */ import_react3.default.createElement(AuthFetch, null), children));
404
+ }
401
405
 
402
406
  // src/auth/email/index.ts
403
- function getEmailAuthRoutes(options) {
407
+ function setupEmailAuth(options) {
404
408
  const { allowedOrigins } = options;
405
409
  return {
406
410
  GET: withCors(getGetRoute(options), allowedOrigins),
@@ -424,7 +428,8 @@ function getEmailAuthRoutes(options) {
424
428
  // Annotate the CommonJS export names for ESM import in node:
425
429
  0 && (module.exports = {
426
430
  AuthFetch,
431
+ AuthWrapper,
427
432
  checkAuthStatus,
428
433
  getContext,
429
- getEmailAuthRoutes
434
+ setupEmailAuth
430
435
  });
@@ -1,10 +1,11 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { InitRoutesOptions } from './types.mjs';
3
- export { default as AuthFetch } from './server.mjs';
2
+ import { SetupEmailAuthOptions } from './types.mjs';
3
+ export { AuthFetch, AuthWrapper } from './next.mjs';
4
4
  export { checkAuthStatus } from './token.mjs';
5
5
  export { getContext } from './utils.mjs';
6
6
  import '../types.mjs';
7
7
  import 'react';
8
+ import './client.mjs';
8
9
  import '../../graphql/types.mjs';
9
10
 
10
11
  /**
@@ -13,7 +14,7 @@ import '../../graphql/types.mjs';
13
14
  * The library automatically hashes passwords on sign-up and reads `SIGNING_KEY` / `REFRESH_KEY` from env vars.
14
15
  * Optionally supports Cloudflare Turnstile captcha validation when `TURNSTILE_KEY` is set.
15
16
  *
16
- * @param options - Configuration for the auth routes. See {@link InitRoutesOptions}.
17
+ * @param options - Configuration for the auth routes. See {@link SetupEmailAuthOptions}.
17
18
  * @param options.getUser - Given request body (e.g. `{ email }`), returns the user from DB or undefined. Used for login and duplicate check on sign-up.
18
19
  * @param options.createUser - Given sign-up data with hashed password, inserts the user and returns the created record.
19
20
  * @param options.onError - Optional. Called on validation/auth errors; return a NextResponse to customize the error response.
@@ -26,9 +27,9 @@ import '../../graphql/types.mjs';
26
27
  * @example
27
28
  * ```ts
28
29
  * // app/api/(auth)/email/route.ts
29
- * import { getEmailAuthRoutes } from "naystack/auth";
30
+ * import { setupEmailAuth } from "naystack/auth";
30
31
  *
31
- * export const { GET, POST, PUT, DELETE } = getEmailAuthRoutes({
32
+ * export const { GET, POST, PUT, DELETE } = setupEmailAuth({
32
33
  * getUser: async ({ email }: { email: string }) => {
33
34
  * const [user] = await db.select({ id: UserTable.id, password: UserTable.password })
34
35
  * .from(UserTable).where(eq(UserTable.email, email));
@@ -47,7 +48,7 @@ import '../../graphql/types.mjs';
47
48
  *
48
49
  * @category Auth
49
50
  */
50
- declare function getEmailAuthRoutes(options: InitRoutesOptions): {
51
+ declare function setupEmailAuth(options: SetupEmailAuthOptions): {
51
52
  OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
52
53
  GET: (req: NextRequest) => Promise<NextResponse<{
53
54
  accessToken: string | undefined;
@@ -61,4 +62,4 @@ declare function getEmailAuthRoutes(options: InitRoutesOptions): {
61
62
  }>>;
62
63
  };
63
64
 
64
- export { getEmailAuthRoutes };
65
+ export { setupEmailAuth };
@@ -1,10 +1,11 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { InitRoutesOptions } from './types.js';
3
- export { default as AuthFetch } from './server.js';
2
+ import { SetupEmailAuthOptions } from './types.js';
3
+ export { AuthFetch, AuthWrapper } from './next.js';
4
4
  export { checkAuthStatus } from './token.js';
5
5
  export { getContext } from './utils.js';
6
6
  import '../types.js';
7
7
  import 'react';
8
+ import './client.js';
8
9
  import '../../graphql/types.js';
9
10
 
10
11
  /**
@@ -13,7 +14,7 @@ import '../../graphql/types.js';
13
14
  * The library automatically hashes passwords on sign-up and reads `SIGNING_KEY` / `REFRESH_KEY` from env vars.
14
15
  * Optionally supports Cloudflare Turnstile captcha validation when `TURNSTILE_KEY` is set.
15
16
  *
16
- * @param options - Configuration for the auth routes. See {@link InitRoutesOptions}.
17
+ * @param options - Configuration for the auth routes. See {@link SetupEmailAuthOptions}.
17
18
  * @param options.getUser - Given request body (e.g. `{ email }`), returns the user from DB or undefined. Used for login and duplicate check on sign-up.
18
19
  * @param options.createUser - Given sign-up data with hashed password, inserts the user and returns the created record.
19
20
  * @param options.onError - Optional. Called on validation/auth errors; return a NextResponse to customize the error response.
@@ -26,9 +27,9 @@ import '../../graphql/types.js';
26
27
  * @example
27
28
  * ```ts
28
29
  * // app/api/(auth)/email/route.ts
29
- * import { getEmailAuthRoutes } from "naystack/auth";
30
+ * import { setupEmailAuth } from "naystack/auth";
30
31
  *
31
- * export const { GET, POST, PUT, DELETE } = getEmailAuthRoutes({
32
+ * export const { GET, POST, PUT, DELETE } = setupEmailAuth({
32
33
  * getUser: async ({ email }: { email: string }) => {
33
34
  * const [user] = await db.select({ id: UserTable.id, password: UserTable.password })
34
35
  * .from(UserTable).where(eq(UserTable.email, email));
@@ -47,7 +48,7 @@ import '../../graphql/types.js';
47
48
  *
48
49
  * @category Auth
49
50
  */
50
- declare function getEmailAuthRoutes(options: InitRoutesOptions): {
51
+ declare function setupEmailAuth(options: SetupEmailAuthOptions): {
51
52
  OPTIONS?: ((req: NextRequest) => NextResponse<unknown>) | undefined;
52
53
  GET: (req: NextRequest) => Promise<NextResponse<{
53
54
  accessToken: string | undefined;
@@ -61,4 +62,4 @@ declare function getEmailAuthRoutes(options: InitRoutesOptions): {
61
62
  }>>;
62
63
  };
63
64
 
64
- export { getEmailAuthRoutes };
65
+ export { setupEmailAuth };
@@ -306,8 +306,8 @@ var getPutRoute = (options) => async (req) => {
306
306
  return handleError(403, "Invalid password", options.onError);
307
307
  };
308
308
 
309
- // src/auth/email/server.tsx
310
- import { AuthApply } from "naystack/auth/email/client";
309
+ // src/auth/email/next.tsx
310
+ import { AuthApply, AuthWrapper as AuthWrapperClient } from "naystack/auth/client";
311
311
  import { cookies as cookies3 } from "next/headers";
312
312
  import React2 from "react";
313
313
 
@@ -345,7 +345,7 @@ var { query: gqlQuery } = registerApolloClient(() => {
345
345
  });
346
346
  });
347
347
 
348
- // src/auth/email/server.tsx
348
+ // src/auth/email/next.tsx
349
349
  function AuthFetch() {
350
350
  return /* @__PURE__ */ React2.createElement(
351
351
  Injector,
@@ -365,9 +365,12 @@ function AuthFetch() {
365
365
  }
366
366
  );
367
367
  }
368
+ function AuthWrapper({ children, getRefreshToken, onTokenUpdate, skipInitialFetch }) {
369
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(AuthWrapperClient, { skipInitialFetch: true, getRefreshToken, onTokenUpdate }, !skipInitialFetch && /* @__PURE__ */ React2.createElement(AuthFetch, null), children));
370
+ }
368
371
 
369
372
  // src/auth/email/index.ts
370
- function getEmailAuthRoutes(options) {
373
+ function setupEmailAuth(options) {
371
374
  const { allowedOrigins } = options;
372
375
  return {
373
376
  GET: withCors(getGetRoute(options), allowedOrigins),
@@ -390,7 +393,8 @@ function getEmailAuthRoutes(options) {
390
393
  }
391
394
  export {
392
395
  AuthFetch,
396
+ AuthWrapper,
393
397
  checkAuthStatus,
394
398
  getContext,
395
- getEmailAuthRoutes
399
+ setupEmailAuth
396
400
  };
@@ -27,13 +27,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/auth/email/server.tsx
31
- var server_exports = {};
32
- __export(server_exports, {
33
- default: () => AuthFetch
30
+ // src/auth/email/next.tsx
31
+ var next_exports = {};
32
+ __export(next_exports, {
33
+ AuthFetch: () => AuthFetch,
34
+ AuthWrapper: () => AuthWrapper
34
35
  });
35
- module.exports = __toCommonJS(server_exports);
36
- var import_client2 = require("naystack/auth/email/client");
36
+ module.exports = __toCommonJS(next_exports);
37
+ var import_client2 = require("naystack/auth/client");
37
38
  var import_headers2 = require("next/headers");
38
39
  var import_react3 = __toESM(require("react"));
39
40
 
@@ -120,7 +121,7 @@ var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloCli
120
121
  });
121
122
  });
122
123
 
123
- // src/auth/email/server.tsx
124
+ // src/auth/email/next.tsx
124
125
  function AuthFetch() {
125
126
  return /* @__PURE__ */ import_react3.default.createElement(
126
127
  Injector,
@@ -140,3 +141,11 @@ function AuthFetch() {
140
141
  }
141
142
  );
142
143
  }
144
+ function AuthWrapper({ children, getRefreshToken, onTokenUpdate, skipInitialFetch }) {
145
+ return /* @__PURE__ */ import_react3.default.createElement(import_react3.default.Fragment, null, /* @__PURE__ */ import_react3.default.createElement(import_client2.AuthWrapper, { skipInitialFetch: true, getRefreshToken, onTokenUpdate }, !skipInitialFetch && /* @__PURE__ */ import_react3.default.createElement(AuthFetch, null), children));
146
+ }
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ AuthFetch,
150
+ AuthWrapper
151
+ });
@@ -0,0 +1,7 @@
1
+ import React__default from 'react';
2
+ import { AuthWrapperProps } from './client.mjs';
3
+
4
+ declare function AuthFetch(): React__default.JSX.Element;
5
+ declare function AuthWrapper({ children, getRefreshToken, onTokenUpdate, skipInitialFetch }: AuthWrapperProps): React__default.JSX.Element;
6
+
7
+ export { AuthFetch, AuthWrapper };
@@ -0,0 +1,7 @@
1
+ import React__default from 'react';
2
+ import { AuthWrapperProps } from './client.js';
3
+
4
+ declare function AuthFetch(): React__default.JSX.Element;
5
+ declare function AuthWrapper({ children, getRefreshToken, onTokenUpdate, skipInitialFetch }: AuthWrapperProps): React__default.JSX.Element;
6
+
7
+ export { AuthFetch, AuthWrapper };
@@ -1,5 +1,5 @@
1
- // src/auth/email/server.tsx
2
- import { AuthApply } from "naystack/auth/email/client";
1
+ // src/auth/email/next.tsx
2
+ import { AuthApply, AuthWrapper as AuthWrapperClient } from "naystack/auth/client";
3
3
  import { cookies as cookies2 } from "next/headers";
4
4
  import React2 from "react";
5
5
 
@@ -90,7 +90,7 @@ var { query: gqlQuery } = registerApolloClient(() => {
90
90
  });
91
91
  });
92
92
 
93
- // src/auth/email/server.tsx
93
+ // src/auth/email/next.tsx
94
94
  function AuthFetch() {
95
95
  return /* @__PURE__ */ React2.createElement(
96
96
  Injector,
@@ -110,6 +110,10 @@ function AuthFetch() {
110
110
  }
111
111
  );
112
112
  }
113
+ function AuthWrapper({ children, getRefreshToken, onTokenUpdate, skipInitialFetch }) {
114
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(AuthWrapperClient, { skipInitialFetch: true, getRefreshToken, onTokenUpdate }, !skipInitialFetch && /* @__PURE__ */ React2.createElement(AuthFetch, null), children));
115
+ }
113
116
  export {
114
- AuthFetch as default
117
+ AuthFetch,
118
+ AuthWrapper
115
119
  };
@@ -1,14 +1,14 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.mjs';
3
+ import { SetupEmailAuthOptions } from '../types.mjs';
4
4
  import '../../types.mjs';
5
5
 
6
6
  /**
7
7
  * Returns the DELETE route handler for logout.
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getDeleteRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
11
+ declare const getDeleteRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
12
12
  accessToken: string | undefined;
13
13
  refreshToken: string | undefined;
14
14
  }>>;
@@ -1,14 +1,14 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.js';
3
+ import { SetupEmailAuthOptions } from '../types.js';
4
4
  import '../../types.js';
5
5
 
6
6
  /**
7
7
  * Returns the DELETE route handler for logout.
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getDeleteRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
11
+ declare const getDeleteRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
12
12
  accessToken: string | undefined;
13
13
  refreshToken: string | undefined;
14
14
  }>>;
@@ -1,14 +1,14 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.mjs';
3
+ import { SetupEmailAuthOptions } from '../types.mjs';
4
4
  import '../../types.mjs';
5
5
 
6
6
  /**
7
7
  * Returns the GET route handler for token refresh (exchange refresh cookie for new tokens).
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getGetRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
11
+ declare const getGetRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
12
12
  accessToken: string | undefined;
13
13
  refreshToken: string | undefined;
14
14
  }>>;
@@ -1,14 +1,14 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.js';
3
+ import { SetupEmailAuthOptions } from '../types.js';
4
4
  import '../../types.js';
5
5
 
6
6
  /**
7
7
  * Returns the GET route handler for token refresh (exchange refresh cookie for new tokens).
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getGetRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
11
+ declare const getGetRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<{
12
12
  accessToken: string | undefined;
13
13
  refreshToken: string | undefined;
14
14
  }>>;
@@ -1,13 +1,13 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.mjs';
3
+ import { SetupEmailAuthOptions } from '../types.mjs';
4
4
  import '../../types.mjs';
5
5
 
6
6
  /**
7
7
  * Returns the POST route handler for sign up.
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getPostRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
11
+ declare const getPostRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
12
12
 
13
13
  export { getPostRoute };
@@ -1,13 +1,13 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.js';
3
+ import { SetupEmailAuthOptions } from '../types.js';
4
4
  import '../../types.js';
5
5
 
6
6
  /**
7
7
  * Returns the POST route handler for sign up.
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getPostRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
11
+ declare const getPostRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
12
12
 
13
13
  export { getPostRoute };
@@ -1,13 +1,13 @@
1
1
  import * as next_server from 'next/server';
2
2
  import { NextRequest } from 'next/server';
3
- import { InitRoutesOptions } from '../types.mjs';
3
+ import { SetupEmailAuthOptions } from '../types.mjs';
4
4
  import '../../types.mjs';
5
5
 
6
6
  /**
7
7
  * Returns the PUT route handler for login.
8
- * @param options - InitRoutesOptions
8
+ * @param options - SetupEmailAuthOptions
9
9
  * @returns Async route handler
10
10
  */
11
- declare const getPutRoute: (options: InitRoutesOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
11
+ declare const getPutRoute: (options: SetupEmailAuthOptions) => (req: NextRequest) => Promise<next_server.NextResponse<unknown> | undefined>;
12
12
 
13
13
  export { getPutRoute };