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,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 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 };
@@ -130,10 +130,10 @@ function getUserIdFromRefreshToken(refreshToken) {
130
130
  }
131
131
  return null;
132
132
  }
133
- function getUserIdFromAccessToken(refreshToken) {
134
- if (refreshToken)
133
+ function getUserIdFromAccessToken(accessToken) {
134
+ if (accessToken)
135
135
  try {
136
- const decoded = (0, import_jsonwebtoken.verify)(refreshToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
136
+ const decoded = (0, import_jsonwebtoken.verify)(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
137
137
  if (typeof decoded !== "string" && typeof decoded.id === "number")
138
138
  return decoded.id;
139
139
  } catch (e) {
@@ -42,11 +42,11 @@ declare function getTokenizedResponse(accessToken?: string, refreshToken?: strin
42
42
  declare function getUserIdFromRefreshToken(refreshToken?: string): number | null;
43
43
  /**
44
44
  * Decodes an access token and returns the user id from the JWT payload.
45
- * @param refreshToken - JWT access token string (parameter name is legacy).
45
+ * @param accessToken - JWT access token string.
46
46
  * @returns User id (number) or `null` if the token is invalid, expired, or missing.
47
47
  * @category Auth
48
48
  */
49
- declare function getUserIdFromAccessToken(refreshToken?: string): number | null;
49
+ declare function getUserIdFromAccessToken(accessToken?: string): number | null;
50
50
  /**
51
51
  * Verifies a plain password against the user's stored bcrypt hash.
52
52
  * @param user - User object with `password` hash.
@@ -42,11 +42,11 @@ declare function getTokenizedResponse(accessToken?: string, refreshToken?: strin
42
42
  declare function getUserIdFromRefreshToken(refreshToken?: string): number | null;
43
43
  /**
44
44
  * Decodes an access token and returns the user id from the JWT payload.
45
- * @param refreshToken - JWT access token string (parameter name is legacy).
45
+ * @param accessToken - JWT access token string.
46
46
  * @returns User id (number) or `null` if the token is invalid, expired, or missing.
47
47
  * @category Auth
48
48
  */
49
- declare function getUserIdFromAccessToken(refreshToken?: string): number | null;
49
+ declare function getUserIdFromAccessToken(accessToken?: string): number | null;
50
50
  /**
51
51
  * Verifies a plain password against the user's stored bcrypt hash.
52
52
  * @param user - User object with `password` hash.
@@ -100,10 +100,10 @@ function getUserIdFromRefreshToken(refreshToken) {
100
100
  }
101
101
  return null;
102
102
  }
103
- function getUserIdFromAccessToken(refreshToken) {
104
- if (refreshToken)
103
+ function getUserIdFromAccessToken(accessToken) {
104
+ if (accessToken)
105
105
  try {
106
- const decoded = verify(refreshToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
106
+ const decoded = verify(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
107
107
  if (typeof decoded !== "string" && typeof decoded.id === "number")
108
108
  return decoded.id;
109
109
  } catch (e) {
@@ -2,7 +2,7 @@ import { UserOutput, ErrorHandler } from '../types.mjs';
2
2
  import 'next/server';
3
3
 
4
4
  /**
5
- * Options for initializing email auth routes (GET/POST/PUT/DELETE) via `getEmailAuthRoutes`.
5
+ * Options for initializing email auth routes (GET/POST/PUT/DELETE) via `setupEmailAuth`.
6
6
  *
7
7
  * @property getUser - Fetches user by request data (e.g. `{ email }`); used for login and sign-up duplicate check. Must return a {@link UserOutput} or `undefined`.
8
8
  * @property createUser - Creates a new user with the hashed password; returns the created user as {@link UserOutput}.
@@ -11,10 +11,11 @@ import 'next/server';
11
11
  * @property onLogin - Optional callback after successful login. Receives `(userId, requestBody)`.
12
12
  * @property onRefresh - Optional callback when GET refresh is used. Receives `(userId, requestBody)`.
13
13
  * @property onLogout - Optional callback when DELETE logout is used. Receives `(userId, requestBody)`.
14
+ * @property allowedOrigins - Optional list of allowed CORS origins. If set, cross-origin requests from unlisted origins are rejected with 403.
14
15
  *
15
16
  * @example
16
17
  * ```ts
17
- * const options: InitRoutesOptions = {
18
+ * const options: SetupEmailAuthOptions = {
18
19
  * getUser: async ({ email }) => db.query.users.findFirst({ where: eq(users.email, email) }),
19
20
  * createUser: async (data) => (await db.insert(users).values(data).returning())[0],
20
21
  * onSignUp: async (userId, body) => { console.log("New user:", userId); },
@@ -23,7 +24,7 @@ import 'next/server';
23
24
  *
24
25
  * @category Auth
25
26
  */
26
- type InitRoutesOptions = {
27
+ type SetupEmailAuthOptions = {
27
28
  getUser: (data: any) => Promise<UserOutput | undefined>;
28
29
  createUser: (user: any) => Promise<UserOutput | undefined>;
29
30
  onError?: ErrorHandler;
@@ -34,4 +35,4 @@ type InitRoutesOptions = {
34
35
  allowedOrigins?: string[];
35
36
  };
36
37
 
37
- export type { InitRoutesOptions };
38
+ export type { SetupEmailAuthOptions };
@@ -2,7 +2,7 @@ import { UserOutput, ErrorHandler } from '../types.js';
2
2
  import 'next/server';
3
3
 
4
4
  /**
5
- * Options for initializing email auth routes (GET/POST/PUT/DELETE) via `getEmailAuthRoutes`.
5
+ * Options for initializing email auth routes (GET/POST/PUT/DELETE) via `setupEmailAuth`.
6
6
  *
7
7
  * @property getUser - Fetches user by request data (e.g. `{ email }`); used for login and sign-up duplicate check. Must return a {@link UserOutput} or `undefined`.
8
8
  * @property createUser - Creates a new user with the hashed password; returns the created user as {@link UserOutput}.
@@ -11,10 +11,11 @@ import 'next/server';
11
11
  * @property onLogin - Optional callback after successful login. Receives `(userId, requestBody)`.
12
12
  * @property onRefresh - Optional callback when GET refresh is used. Receives `(userId, requestBody)`.
13
13
  * @property onLogout - Optional callback when DELETE logout is used. Receives `(userId, requestBody)`.
14
+ * @property allowedOrigins - Optional list of allowed CORS origins. If set, cross-origin requests from unlisted origins are rejected with 403.
14
15
  *
15
16
  * @example
16
17
  * ```ts
17
- * const options: InitRoutesOptions = {
18
+ * const options: SetupEmailAuthOptions = {
18
19
  * getUser: async ({ email }) => db.query.users.findFirst({ where: eq(users.email, email) }),
19
20
  * createUser: async (data) => (await db.insert(users).values(data).returning())[0],
20
21
  * onSignUp: async (userId, body) => { console.log("New user:", userId); },
@@ -23,7 +24,7 @@ import 'next/server';
23
24
  *
24
25
  * @category Auth
25
26
  */
26
- type InitRoutesOptions = {
27
+ type SetupEmailAuthOptions = {
27
28
  getUser: (data: any) => Promise<UserOutput | undefined>;
28
29
  createUser: (user: any) => Promise<UserOutput | undefined>;
29
30
  onError?: ErrorHandler;
@@ -34,4 +35,4 @@ type InitRoutesOptions = {
34
35
  allowedOrigins?: string[];
35
36
  };
36
37
 
37
- export type { InitRoutesOptions };
38
+ export type { SetupEmailAuthOptions };
@@ -1,6 +1,6 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
  import { Context } from '../../graphql/types.mjs';
3
- import { InitRoutesOptions } from './types.mjs';
3
+ import { SetupEmailAuthOptions } from './types.mjs';
4
4
  import '../types.mjs';
5
5
 
6
6
  /**
@@ -8,11 +8,11 @@ import '../types.mjs';
8
8
  * if `TURNSTILE_KEY` is set, validates the Cloudflare Turnstile captcha.
9
9
  *
10
10
  * @param req - The NextRequest (body is read via `req.json()`).
11
- * @param options - Same `InitRoutesOptions` passed to `getEmailAuthRoutes`; used for `onError` when validation fails.
11
+ * @param options - Same `SetupEmailAuthOptions` passed to `setupEmailAuth`; used for `onError` when validation fails.
12
12
  * @returns Promise of either `{ error: NextResponse }` (validation failed) or `{ data: { password, ...rest } }` with the validated payload.
13
13
  * @category Auth
14
14
  */
15
- declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
15
+ declare function massageRequest(req: NextRequest, options: SetupEmailAuthOptions): Promise<{
16
16
  error?: NextResponse;
17
17
  data?: {
18
18
  password: string;
@@ -1,6 +1,6 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
  import { Context } from '../../graphql/types.js';
3
- import { InitRoutesOptions } from './types.js';
3
+ import { SetupEmailAuthOptions } from './types.js';
4
4
  import '../types.js';
5
5
 
6
6
  /**
@@ -8,11 +8,11 @@ import '../types.js';
8
8
  * if `TURNSTILE_KEY` is set, validates the Cloudflare Turnstile captcha.
9
9
  *
10
10
  * @param req - The NextRequest (body is read via `req.json()`).
11
- * @param options - Same `InitRoutesOptions` passed to `getEmailAuthRoutes`; used for `onError` when validation fails.
11
+ * @param options - Same `SetupEmailAuthOptions` passed to `setupEmailAuth`; used for `onError` when validation fails.
12
12
  * @returns Promise of either `{ error: NextResponse }` (validation failed) or `{ data: { password, ...rest } }` with the validated payload.
13
13
  * @category Auth
14
14
  */
15
- declare function massageRequest(req: NextRequest, options: InitRoutesOptions): Promise<{
15
+ declare function massageRequest(req: NextRequest, options: SetupEmailAuthOptions): Promise<{
16
16
  error?: NextResponse;
17
17
  data?: {
18
18
  password: string;
@@ -1,12 +1,12 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { InitGoogleAuthOptions } from './index.mjs';
2
+ import { SetupGoogleAuthOptions } from './index.mjs';
3
3
  import 'googleapis';
4
4
 
5
5
  /**
6
6
  * Returns the GET route handler for Google OAuth (initiate and callback).
7
- * @param options - InitGoogleAuthOptions
7
+ * @param options - SetupGoogleAuthOptions
8
8
  * @returns Async route handler
9
9
  */
10
- declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
10
+ declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: SetupGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
11
11
 
12
12
  export { getGoogleGetRoute };
@@ -1,12 +1,12 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- import { InitGoogleAuthOptions } from './index.js';
2
+ import { SetupGoogleAuthOptions } from './index.js';
3
3
  import 'googleapis';
4
4
 
5
5
  /**
6
6
  * Returns the GET route handler for Google OAuth (initiate and callback).
7
- * @param options - InitGoogleAuthOptions
7
+ * @param options - SetupGoogleAuthOptions
8
8
  * @returns Async route handler
9
9
  */
10
- declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: InitGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
10
+ declare const getGoogleGetRoute: ({ getUserIdFromEmail, redirectURL, errorRedirectURL, }: SetupGoogleAuthOptions) => (req: NextRequest) => Promise<NextResponse<unknown>>;
11
11
 
12
12
  export { getGoogleGetRoute };
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/auth/google/index.ts
21
21
  var google_exports = {};
22
22
  __export(google_exports, {
23
- initGoogleAuth: () => initGoogleAuth
23
+ setupGoogleAuth: () => setupGoogleAuth
24
24
  });
25
25
  module.exports = __toCommonJS(google_exports);
26
26
 
@@ -172,12 +172,12 @@ var getGoogleGetRoute = ({
172
172
  };
173
173
 
174
174
  // src/auth/google/index.ts
175
- function initGoogleAuth(props) {
175
+ function setupGoogleAuth(props) {
176
176
  return {
177
177
  GET: getGoogleGetRoute(props)
178
178
  };
179
179
  }
180
180
  // Annotate the CommonJS export names for ESM import in node:
181
181
  0 && (module.exports = {
182
- initGoogleAuth
182
+ setupGoogleAuth
183
183
  });
@@ -4,7 +4,7 @@ import { oauth2_v2 } from 'googleapis';
4
4
  /** Google OAuth userinfo schema (from googleapis). */
5
5
  type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
6
6
  /**
7
- * Options for initializing Google OAuth via {@link initGoogleAuth}.
7
+ * Options for initializing Google OAuth via {@link setupGoogleAuth}.
8
8
  *
9
9
  * @property getUserIdFromEmail - Given Google userinfo (email, name, picture, etc.), resolves to your app's user id. Return `null` if the user should not be authenticated.
10
10
  * @property redirectURL - Where to redirect after successful Google auth (e.g. `"/dashboard"`).
@@ -12,7 +12,7 @@ type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
12
12
  *
13
13
  * @category Auth
14
14
  */
15
- interface InitGoogleAuthOptions {
15
+ interface SetupGoogleAuthOptions {
16
16
  getUserIdFromEmail: (email: Schema$Userinfo, data?: string) => Promise<number | null>;
17
17
  redirectURL: string;
18
18
  errorRedirectURL?: string;
@@ -25,15 +25,15 @@ interface InitGoogleAuthOptions {
25
25
  *
26
26
  * Requires env vars: `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT`.
27
27
  *
28
- * @param props - Options. See {@link InitGoogleAuthOptions}.
28
+ * @param props - Options. See {@link SetupGoogleAuthOptions}.
29
29
  * @returns Object with `GET` — export as your route's GET handler.
30
30
  *
31
31
  * @example
32
32
  * ```ts
33
33
  * // app/api/(auth)/google/route.ts
34
- * import { initGoogleAuth } from "naystack/auth";
34
+ * import { setupGoogleAuth } from "naystack/auth";
35
35
  *
36
- * export const { GET } = initGoogleAuth({
36
+ * export const { GET } = setupGoogleAuth({
37
37
  * getUserIdFromEmail: async (googleUser) => {
38
38
  * // Find or create user by Google email
39
39
  * const user = await findOrCreateUserByEmail(googleUser.email!);
@@ -46,8 +46,8 @@ interface InitGoogleAuthOptions {
46
46
  *
47
47
  * @category Auth
48
48
  */
49
- declare function initGoogleAuth(props: InitGoogleAuthOptions): {
49
+ declare function setupGoogleAuth(props: SetupGoogleAuthOptions): {
50
50
  GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
51
51
  };
52
52
 
53
- export { type InitGoogleAuthOptions, initGoogleAuth };
53
+ export { type SetupGoogleAuthOptions, setupGoogleAuth };
@@ -4,7 +4,7 @@ import { oauth2_v2 } from 'googleapis';
4
4
  /** Google OAuth userinfo schema (from googleapis). */
5
5
  type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
6
6
  /**
7
- * Options for initializing Google OAuth via {@link initGoogleAuth}.
7
+ * Options for initializing Google OAuth via {@link setupGoogleAuth}.
8
8
  *
9
9
  * @property getUserIdFromEmail - Given Google userinfo (email, name, picture, etc.), resolves to your app's user id. Return `null` if the user should not be authenticated.
10
10
  * @property redirectURL - Where to redirect after successful Google auth (e.g. `"/dashboard"`).
@@ -12,7 +12,7 @@ type Schema$Userinfo = oauth2_v2.Schema$Userinfo;
12
12
  *
13
13
  * @category Auth
14
14
  */
15
- interface InitGoogleAuthOptions {
15
+ interface SetupGoogleAuthOptions {
16
16
  getUserIdFromEmail: (email: Schema$Userinfo, data?: string) => Promise<number | null>;
17
17
  redirectURL: string;
18
18
  errorRedirectURL?: string;
@@ -25,15 +25,15 @@ interface InitGoogleAuthOptions {
25
25
  *
26
26
  * Requires env vars: `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `NEXT_PUBLIC_GOOGLE_AUTH_ENDPOINT`.
27
27
  *
28
- * @param props - Options. See {@link InitGoogleAuthOptions}.
28
+ * @param props - Options. See {@link SetupGoogleAuthOptions}.
29
29
  * @returns Object with `GET` — export as your route's GET handler.
30
30
  *
31
31
  * @example
32
32
  * ```ts
33
33
  * // app/api/(auth)/google/route.ts
34
- * import { initGoogleAuth } from "naystack/auth";
34
+ * import { setupGoogleAuth } from "naystack/auth";
35
35
  *
36
- * export const { GET } = initGoogleAuth({
36
+ * export const { GET } = setupGoogleAuth({
37
37
  * getUserIdFromEmail: async (googleUser) => {
38
38
  * // Find or create user by Google email
39
39
  * const user = await findOrCreateUserByEmail(googleUser.email!);
@@ -46,8 +46,8 @@ interface InitGoogleAuthOptions {
46
46
  *
47
47
  * @category Auth
48
48
  */
49
- declare function initGoogleAuth(props: InitGoogleAuthOptions): {
49
+ declare function setupGoogleAuth(props: SetupGoogleAuthOptions): {
50
50
  GET: (req: next_server.NextRequest) => Promise<next_server.NextResponse<unknown>>;
51
51
  };
52
52
 
53
- export { type InitGoogleAuthOptions, initGoogleAuth };
53
+ export { type SetupGoogleAuthOptions, setupGoogleAuth };
@@ -146,11 +146,11 @@ var getGoogleGetRoute = ({
146
146
  };
147
147
 
148
148
  // src/auth/google/index.ts
149
- function initGoogleAuth(props) {
149
+ function setupGoogleAuth(props) {
150
150
  return {
151
151
  GET: getGoogleGetRoute(props)
152
152
  };
153
153
  }
154
154
  export {
155
- initGoogleAuth
155
+ setupGoogleAuth
156
156
  };
@@ -33,11 +33,11 @@ __export(auth_exports, {
33
33
  AuthFetch: () => AuthFetch,
34
34
  checkAuthStatus: () => checkAuthStatus,
35
35
  getContext: () => getContext,
36
- getEmailAuthRoutes: () => getEmailAuthRoutes,
37
36
  getRefreshToken: () => getRefreshToken,
38
37
  getRefreshedInstagramAccessToken: () => getRefreshedInstagramAccessToken,
39
- initGoogleAuth: () => initGoogleAuth,
40
- initInstagramAuth: () => initInstagramAuth
38
+ setupEmailAuth: () => setupEmailAuth,
39
+ setupGoogleAuth: () => setupGoogleAuth,
40
+ setupInstagramAuth: () => setupInstagramAuth
41
41
  });
42
42
  module.exports = __toCommonJS(auth_exports);
43
43
 
@@ -178,10 +178,10 @@ function getUserIdFromRefreshToken(refreshToken) {
178
178
  }
179
179
  return null;
180
180
  }
181
- function getUserIdFromAccessToken(refreshToken) {
182
- if (refreshToken)
181
+ function getUserIdFromAccessToken(accessToken) {
182
+ if (accessToken)
183
183
  try {
184
- const decoded = (0, import_jsonwebtoken.verify)(refreshToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
184
+ const decoded = (0, import_jsonwebtoken.verify)(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
185
185
  if (typeof decoded !== "string" && typeof decoded.id === "number")
186
186
  return decoded.id;
187
187
  } catch (e) {
@@ -361,8 +361,8 @@ var getPutRoute = (options) => async (req) => {
361
361
  return handleError(403, "Invalid password", options.onError);
362
362
  };
363
363
 
364
- // src/auth/email/server.tsx
365
- var import_client2 = require("naystack/auth/email/client");
364
+ // src/auth/email/next.tsx
365
+ var import_client2 = require("naystack/auth/client");
366
366
  var import_headers3 = require("next/headers");
367
367
  var import_react3 = __toESM(require("react"));
368
368
 
@@ -396,7 +396,7 @@ var { query: gqlQuery } = (0, import_client_integration_nextjs.registerApolloCli
396
396
  });
397
397
  });
398
398
 
399
- // src/auth/email/server.tsx
399
+ // src/auth/email/next.tsx
400
400
  function AuthFetch() {
401
401
  return /* @__PURE__ */ import_react3.default.createElement(
402
402
  Injector,
@@ -418,7 +418,7 @@ function AuthFetch() {
418
418
  }
419
419
 
420
420
  // src/auth/email/index.ts
421
- function getEmailAuthRoutes(options) {
421
+ function setupEmailAuth(options) {
422
422
  const { allowedOrigins } = options;
423
423
  return {
424
424
  GET: withCors(getGetRoute(options), allowedOrigins),
@@ -442,7 +442,7 @@ function getEmailAuthRoutes(options) {
442
442
 
443
443
  // src/auth/google/get.ts
444
444
  var import_googleapis = require("googleapis");
445
- var import_server7 = require("next/server");
445
+ var import_server6 = require("next/server");
446
446
  var import_uuid = require("uuid");
447
447
  var getGoogleGetRoute = ({
448
448
  getUserIdFromEmail,
@@ -472,7 +472,7 @@ var getGoogleGetRoute = ({
472
472
  prompt: "consent",
473
473
  redirect_uri: url
474
474
  });
475
- const res = import_server7.NextResponse.redirect(authorizationUrl);
475
+ const res = import_server6.NextResponse.redirect(authorizationUrl);
476
476
  res.cookies.set("state", state2, {
477
477
  httpOnly: true,
478
478
  secure: true
@@ -481,12 +481,12 @@ var getGoogleGetRoute = ({
481
481
  }
482
482
  const errorURL = errorRedirectURL || redirectURL;
483
483
  if (error) {
484
- return import_server7.NextResponse.redirect(errorURL);
484
+ return import_server6.NextResponse.redirect(errorURL);
485
485
  }
486
486
  const state = req.nextUrl.searchParams.get("state") || void 0;
487
487
  if (code && state) {
488
488
  const localState = req.cookies.get("state")?.value;
489
- if (localState !== state) return import_server7.NextResponse.redirect(errorURL);
489
+ if (localState !== state) return import_server6.NextResponse.redirect(errorURL);
490
490
  const { tokens } = await oauth2Client.getToken(code);
491
491
  oauth2Client.setCredentials(tokens);
492
492
  const userInfoRequest = await import_googleapis.google.oauth2({
@@ -498,7 +498,7 @@ var getGoogleGetRoute = ({
498
498
  const { data } = JSON.parse(localState);
499
499
  const id = await getUserIdFromEmail(user, data);
500
500
  if (id) {
501
- const res = import_server7.NextResponse.redirect(redirectURL);
501
+ const res = import_server6.NextResponse.redirect(redirectURL);
502
502
  res.cookies.set(
503
503
  REFRESH_COOKIE_NAME,
504
504
  generateRefreshToken(id, getEnv("REFRESH_KEY" /* REFRESH_KEY */)),
@@ -516,19 +516,19 @@ var getGoogleGetRoute = ({
516
516
  }
517
517
  }
518
518
  }
519
- return import_server7.NextResponse.redirect(errorURL);
519
+ return import_server6.NextResponse.redirect(errorURL);
520
520
  };
521
521
  };
522
522
 
523
523
  // src/auth/google/index.ts
524
- function initGoogleAuth(props) {
524
+ function setupGoogleAuth(props) {
525
525
  return {
526
526
  GET: getGoogleGetRoute(props)
527
527
  };
528
528
  }
529
529
 
530
530
  // src/auth/instagram/route.ts
531
- var import_server9 = require("next/server");
531
+ var import_server8 = require("next/server");
532
532
 
533
533
  // src/auth/instagram/utils.ts
534
534
  async function getRefreshedInstagramAccessToken(token) {
@@ -590,7 +590,7 @@ var getInstagramUser = (token, id, fields) => {
590
590
  };
591
591
 
592
592
  // src/socials/meta-webhook.ts
593
- var import_server8 = require("next/server");
593
+ var import_server7 = require("next/server");
594
594
 
595
595
  // src/auth/instagram/route.ts
596
596
  var getInstagramRoute = ({
@@ -598,7 +598,7 @@ var getInstagramRoute = ({
598
598
  errorRedirectURL,
599
599
  onUser
600
600
  }) => {
601
- const handleError2 = (message) => import_server9.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
601
+ const handleError2 = (message) => import_server8.NextResponse.redirect(`${errorRedirectURL}?error=${message}`);
602
602
  return async (req) => {
603
603
  const accessCode = req.nextUrl.searchParams.get("code");
604
604
  const error = req.nextUrl.searchParams.get("error");
@@ -622,12 +622,12 @@ var getInstagramRoute = ({
622
622
  instagramData.accessToken
623
623
  );
624
624
  if (errorMessage) return handleError2(errorMessage);
625
- return import_server9.NextResponse.redirect(redirectURL);
625
+ return import_server8.NextResponse.redirect(redirectURL);
626
626
  };
627
627
  };
628
628
 
629
629
  // src/auth/instagram/index.ts
630
- function initInstagramAuth(props) {
630
+ function setupInstagramAuth(props) {
631
631
  return {
632
632
  GET: getInstagramRoute(props)
633
633
  };
@@ -644,9 +644,9 @@ async function getRefreshToken() {
644
644
  AuthFetch,
645
645
  checkAuthStatus,
646
646
  getContext,
647
- getEmailAuthRoutes,
648
647
  getRefreshToken,
649
648
  getRefreshedInstagramAccessToken,
650
- initGoogleAuth,
651
- initInstagramAuth
649
+ setupEmailAuth,
650
+ setupGoogleAuth,
651
+ setupInstagramAuth
652
652
  });
@@ -1,8 +1,8 @@
1
- export { getEmailAuthRoutes } from './email/index.mjs';
2
- export { initGoogleAuth } from './google/index.mjs';
3
- export { initInstagramAuth } from './instagram/index.mjs';
1
+ export { setupEmailAuth } from './email/index.mjs';
2
+ export { setupGoogleAuth } from './google/index.mjs';
3
+ export { setupInstagramAuth } from './instagram/index.mjs';
4
4
  export { getRefreshToken } from './utils/token.mjs';
5
- export { default as AuthFetch } from './email/server.mjs';
5
+ export { AuthFetch } from './email/next.mjs';
6
6
  export { checkAuthStatus } from './email/token.mjs';
7
7
  export { getContext } from './email/utils.mjs';
8
8
  export { getRefreshedInstagramAccessToken } from './instagram/utils.mjs';
@@ -12,4 +12,5 @@ import './types.mjs';
12
12
  import 'googleapis';
13
13
  import '../socials/instagram/types.mjs';
14
14
  import 'react';
15
+ import './email/client.mjs';
15
16
  import '../graphql/types.mjs';
@@ -1,8 +1,8 @@
1
- export { getEmailAuthRoutes } from './email/index.js';
2
- export { initGoogleAuth } from './google/index.js';
3
- export { initInstagramAuth } from './instagram/index.js';
1
+ export { setupEmailAuth } from './email/index.js';
2
+ export { setupGoogleAuth } from './google/index.js';
3
+ export { setupInstagramAuth } from './instagram/index.js';
4
4
  export { getRefreshToken } from './utils/token.js';
5
- export { default as AuthFetch } from './email/server.js';
5
+ export { AuthFetch } from './email/next.js';
6
6
  export { checkAuthStatus } from './email/token.js';
7
7
  export { getContext } from './email/utils.js';
8
8
  export { getRefreshedInstagramAccessToken } from './instagram/utils.js';
@@ -12,4 +12,5 @@ import './types.js';
12
12
  import 'googleapis';
13
13
  import '../socials/instagram/types.js';
14
14
  import 'react';
15
+ import './email/client.js';
15
16
  import '../graphql/types.js';
@@ -135,10 +135,10 @@ function getUserIdFromRefreshToken(refreshToken) {
135
135
  }
136
136
  return null;
137
137
  }
138
- function getUserIdFromAccessToken(refreshToken) {
139
- if (refreshToken)
138
+ function getUserIdFromAccessToken(accessToken) {
139
+ if (accessToken)
140
140
  try {
141
- const decoded = verify(refreshToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
141
+ const decoded = verify(accessToken, getEnv("SIGNING_KEY" /* SIGNING_KEY */));
142
142
  if (typeof decoded !== "string" && typeof decoded.id === "number")
143
143
  return decoded.id;
144
144
  } catch (e) {
@@ -318,8 +318,8 @@ var getPutRoute = (options) => async (req) => {
318
318
  return handleError(403, "Invalid password", options.onError);
319
319
  };
320
320
 
321
- // src/auth/email/server.tsx
322
- import { AuthApply } from "naystack/auth/email/client";
321
+ // src/auth/email/next.tsx
322
+ import { AuthApply, AuthWrapper as AuthWrapperClient } from "naystack/auth/client";
323
323
  import { cookies as cookies3 } from "next/headers";
324
324
  import React2 from "react";
325
325
 
@@ -357,7 +357,7 @@ var { query: gqlQuery } = registerApolloClient(() => {
357
357
  });
358
358
  });
359
359
 
360
- // src/auth/email/server.tsx
360
+ // src/auth/email/next.tsx
361
361
  function AuthFetch() {
362
362
  return /* @__PURE__ */ React2.createElement(
363
363
  Injector,
@@ -379,7 +379,7 @@ function AuthFetch() {
379
379
  }
380
380
 
381
381
  // src/auth/email/index.ts
382
- function getEmailAuthRoutes(options) {
382
+ function setupEmailAuth(options) {
383
383
  const { allowedOrigins } = options;
384
384
  return {
385
385
  GET: withCors(getGetRoute(options), allowedOrigins),
@@ -482,7 +482,7 @@ var getGoogleGetRoute = ({
482
482
  };
483
483
 
484
484
  // src/auth/google/index.ts
485
- function initGoogleAuth(props) {
485
+ function setupGoogleAuth(props) {
486
486
  return {
487
487
  GET: getGoogleGetRoute(props)
488
488
  };
@@ -588,7 +588,7 @@ var getInstagramRoute = ({
588
588
  };
589
589
 
590
590
  // src/auth/instagram/index.ts
591
- function initInstagramAuth(props) {
591
+ function setupInstagramAuth(props) {
592
592
  return {
593
593
  GET: getInstagramRoute(props)
594
594
  };
@@ -604,9 +604,9 @@ export {
604
604
  AuthFetch,
605
605
  checkAuthStatus,
606
606
  getContext,
607
- getEmailAuthRoutes,
608
607
  getRefreshToken,
609
608
  getRefreshedInstagramAccessToken,
610
- initGoogleAuth,
611
- initInstagramAuth
609
+ setupEmailAuth,
610
+ setupGoogleAuth,
611
+ setupInstagramAuth
612
612
  };