nextjs-hasura-auth 0.1.2 → 0.1.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.
@@ -0,0 +1,353 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.useSubscribe = exports.useDelete = exports.useUpdate = exports.useInsert = exports.useSelect = exports.Client = void 0;
27
+ exports.useClient = useClient;
28
+ exports.useQuery = useQuery;
29
+ exports.useSubscription = useSubscription;
30
+ exports.useMutation = useMutation;
31
+ const client_1 = require("@apollo/client");
32
+ const react_1 = require("react");
33
+ const client_2 = require("@apollo/client");
34
+ const debug_1 = __importDefault(require("./debug"));
35
+ const generator_1 = __importDefault(require("./generator"));
36
+ const debug = (0, debug_1.default)('nha:client');
37
+ class Client {
38
+ constructor(apolloClient) {
39
+ if (!apolloClient) {
40
+ throw new Error('❌ ApolloClient instance must be provided to the Client constructor.');
41
+ }
42
+ this.apolloClient = apolloClient;
43
+ this.generate = generator_1.default; // Use the imported generator function
44
+ debug('Client class initialized with ApolloClient instance.');
45
+ }
46
+ /**
47
+ * Executes a GraphQL query (select operation).
48
+ * @param options - Options for generating the query, including an optional `role`.
49
+ * @returns Promise resolving with the query result data.
50
+ * @throws ApolloError if the query fails or returns GraphQL errors.
51
+ */
52
+ select(options) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const { role } = options, genOptions = __rest(options, ["role"]); // Extract role
55
+ debug('Executing select with options:', genOptions, 'Role:', role);
56
+ const generated = this.generate(Object.assign(Object.assign({}, genOptions), { operation: 'query' }));
57
+ try {
58
+ const result = yield this.apolloClient.query({
59
+ query: generated.query,
60
+ variables: generated.variables,
61
+ fetchPolicy: 'network-only', // Ensure fresh data for direct calls
62
+ context: role ? { role } : undefined, // Pass role in context
63
+ });
64
+ if (result.errors) {
65
+ debug('GraphQL errors during select:', result.errors);
66
+ throw new client_1.ApolloError({ graphQLErrors: result.errors });
67
+ }
68
+ debug('Select successful, returning data.');
69
+ return result.data;
70
+ }
71
+ catch (error) {
72
+ debug('Error during select:', error);
73
+ throw error; // Re-throw original error (could be ApolloError or network error)
74
+ }
75
+ });
76
+ }
77
+ /**
78
+ * Executes a GraphQL insert mutation.
79
+ * @param options - Options for generating the mutation, including an optional `role`.
80
+ * @returns Promise resolving with the mutation result data.
81
+ * @throws ApolloError if the mutation fails or returns GraphQL errors.
82
+ */
83
+ insert(options) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ var _a;
86
+ const { role } = options, genOptions = __rest(options, ["role"]); // Extract role
87
+ debug('Executing insert with options:', genOptions, 'Role:', role);
88
+ const generated = this.generate(Object.assign(Object.assign({}, genOptions), { operation: 'insert' }));
89
+ try {
90
+ const result = yield this.apolloClient.mutate({
91
+ mutation: generated.query,
92
+ variables: generated.variables,
93
+ context: role ? { role } : undefined, // Pass role in context
94
+ });
95
+ if (result.errors) {
96
+ debug('GraphQL errors during insert:', result.errors);
97
+ throw new client_1.ApolloError({ graphQLErrors: result.errors });
98
+ }
99
+ // Check if data exists, otherwise return an empty object or handle as needed
100
+ const returnData = (_a = result.data) !== null && _a !== void 0 ? _a : {};
101
+ debug('Insert successful, returning data.');
102
+ return returnData;
103
+ }
104
+ catch (error) {
105
+ debug('Error during insert:', error);
106
+ throw error;
107
+ }
108
+ });
109
+ }
110
+ /**
111
+ * Executes a GraphQL update mutation.
112
+ * @param options - Options for generating the mutation, including an optional `role`.
113
+ * @returns Promise resolving with the mutation result data.
114
+ * @throws ApolloError if the mutation fails or returns GraphQL errors.
115
+ */
116
+ update(options) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ var _a;
119
+ const { role } = options, genOptions = __rest(options, ["role"]); // Extract role
120
+ debug('Executing update with options:', genOptions, 'Role:', role);
121
+ const generated = this.generate(Object.assign(Object.assign({}, genOptions), { operation: 'update' }));
122
+ try {
123
+ const result = yield this.apolloClient.mutate({
124
+ mutation: generated.query,
125
+ variables: generated.variables,
126
+ context: role ? { role } : undefined, // Pass role in context
127
+ });
128
+ if (result.errors) {
129
+ debug('GraphQL errors during update:', result.errors);
130
+ throw new client_1.ApolloError({ graphQLErrors: result.errors });
131
+ }
132
+ const returnData = (_a = result.data) !== null && _a !== void 0 ? _a : {};
133
+ debug('Update successful, returning data.');
134
+ return returnData;
135
+ }
136
+ catch (error) {
137
+ debug('Error during update:', error);
138
+ throw error;
139
+ }
140
+ });
141
+ }
142
+ /**
143
+ * Executes a GraphQL delete mutation.
144
+ * @param options - Options for generating the mutation, including an optional `role`.
145
+ * @returns Promise resolving with the mutation result data.
146
+ * @throws ApolloError if the mutation fails or returns GraphQL errors.
147
+ */
148
+ delete(options) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ var _a;
151
+ const { role } = options, genOptions = __rest(options, ["role"]); // Extract role
152
+ debug('Executing delete with options:', genOptions, 'Role:', role);
153
+ const generated = this.generate(Object.assign(Object.assign({}, genOptions), { operation: 'delete' }));
154
+ try {
155
+ const result = yield this.apolloClient.mutate({
156
+ mutation: generated.query,
157
+ variables: generated.variables,
158
+ context: role ? { role } : undefined, // Pass role in context
159
+ });
160
+ if (result.errors) {
161
+ debug('GraphQL errors during delete:', result.errors);
162
+ throw new client_1.ApolloError({ graphQLErrors: result.errors });
163
+ }
164
+ const returnData = (_a = result.data) !== null && _a !== void 0 ? _a : {};
165
+ debug('Delete successful, returning data.');
166
+ return returnData;
167
+ }
168
+ catch (error) {
169
+ debug('Error during delete:', error);
170
+ throw error;
171
+ }
172
+ });
173
+ }
174
+ /**
175
+ * Initiates a GraphQL subscription.
176
+ * Note: Role support via context might not work for WebSockets depending on Apollo Link setup.
177
+ * Role is typically set during WebSocket connection establishment.
178
+ * @param options - Options for generating the subscription, including an optional `role`.
179
+ * @returns An Observable for the subscription results.
180
+ */
181
+ subscribe(options) {
182
+ const { role } = options, genOptions = __rest(options, ["role"]); // Extract role
183
+ debug('Initiating subscribe with options:', genOptions, 'Role:', role);
184
+ const generated = this.generate(Object.assign(Object.assign({}, genOptions), { operation: 'subscription' }));
185
+ return this.apolloClient.subscribe({
186
+ query: generated.query,
187
+ variables: generated.variables,
188
+ context: role ? { role } : undefined, // Pass role, effectiveness depends on link chain
189
+ });
190
+ }
191
+ useSubscription(
192
+ // First arg: Generator options (table, returning, where, etc.)
193
+ generateOptions,
194
+ // Second arg: Hook options (Apollo options + role)
195
+ hookOptions // Allow variables here for subscription
196
+ ) {
197
+ return useSubscription(generateOptions, (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, hookOptions), { client: this.apolloClient })), [hookOptions]));
198
+ }
199
+ ;
200
+ useQuery(
201
+ // First arg: Generator options (table, returning, where, etc.)
202
+ generateOptions,
203
+ // Second arg: Hook options (Apollo options + role)
204
+ hookOptions // Allow variables here for query
205
+ ) {
206
+ return useQuery(generateOptions, (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, hookOptions), { client: this.apolloClient })), [hookOptions]));
207
+ }
208
+ }
209
+ exports.Client = Client;
210
+ // --- React Hooks ---
211
+ /**
212
+ * Hook to get the Apollo Client instance.
213
+ * Prefers the explicitly provided client, falls back to context, throws if none found.
214
+ * @param providedClient - An optional ApolloClient instance.
215
+ * @returns The ApolloClient instance.
216
+ * @throws Error if no client is found.
217
+ */
218
+ function useClient(providedClient) {
219
+ const ApolloContext = (0, client_1.getApolloContext)();
220
+ const contextValue = (0, react_1.useContext)(ApolloContext);
221
+ const contextClient = contextValue === null || contextValue === void 0 ? void 0 : contextValue.client;
222
+ const client = providedClient !== null && providedClient !== void 0 ? providedClient : contextClient;
223
+ if (!client) {
224
+ throw new Error('❌ useClient: No ApolloClient instance found. Provide one directly or ensure the component is wrapped in an ApolloProvider.');
225
+ }
226
+ return (0, react_1.useMemo)(() => new Client(client), [client]);
227
+ }
228
+ // Helper to extract Apollo options and context for HOOKS
229
+ // Adjusted to not expect variables in mutation options directly
230
+ function prepareHookArgs(options, isMutation = false) {
231
+ const _a = options || {}, { role } = _a, apolloOptions = __rest(_a, ["role"]);
232
+ const context = role ? { role } : undefined;
233
+ // Extract variables only if not a mutation (variables are passed to mutate fn)
234
+ // And if options actually contain variables (e.g., for query/sub)
235
+ const variables = !isMutation && options && 'variables' in options ? options.variables : undefined;
236
+ debug('Preparing hook args', { role, context, variables: isMutation ? '(mutation - in mutate fn)' : variables, apolloOptions });
237
+ return { context, variables, apolloOptions };
238
+ }
239
+ // Standalone Hooks
240
+ function useQuery(
241
+ // First arg: Generator options (table, returning, where, etc.)
242
+ generateOptions,
243
+ // Second arg: Hook options (Apollo options + role)
244
+ hookOptions // Allow variables here for query
245
+ ) {
246
+ var _a, _b;
247
+ const client = (0, client_2.useApolloClient)(); // Use client from context
248
+ // Generate query using the imported 'generate' function
249
+ const { query: queryString, variables: generatedVariables, varCounter } = (0, react_1.useMemo)(() => (0, generator_1.default)(Object.assign({ operation: 'query' }, generateOptions)), [generateOptions]);
250
+ // Ensure gql receives a string
251
+ const query = (0, react_1.useMemo)(() => (0, client_1.gql) `${queryString}`, [queryString]);
252
+ // Combine variables from generator and hook options (hook options override)
253
+ // Cast the combined object to TVariables
254
+ const combinedVariables = Object.assign(Object.assign({}, generatedVariables), hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.variables);
255
+ // Prepare arguments for the actual Apollo hook
256
+ const { context, apolloOptions } = prepareHookArgs(hookOptions, false);
257
+ const operationName = ((_a = query.definitions[0]) === null || _a === void 0 ? void 0 : _a.kind) === 'OperationDefinition' ? ((_b = query.definitions[0].name) === null || _b === void 0 ? void 0 : _b.value) || 'UnnamedQuery' : 'UnnamedQuery';
258
+ debug(`Executing query ${operationName}`, { query: queryString, variables: combinedVariables, context, options: apolloOptions });
259
+ const result = (0, client_2.useQuery)(query, Object.assign({ client, variables: combinedVariables, context }, apolloOptions));
260
+ debug(`Query ${operationName} result`, { loading: result.loading, error: result.error, data: !!result.data });
261
+ return result;
262
+ }
263
+ function useSubscription(
264
+ // First arg: Generator options (table, returning, where, etc.)
265
+ generateOptions,
266
+ // Second arg: Hook options (Apollo options + role)
267
+ hookOptions // Allow variables here for subscription
268
+ ) {
269
+ var _a, _b, _c;
270
+ const apolloClient = (0, client_2.useApolloClient)(); // Use client from context
271
+ const client = (_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.client) !== null && _a !== void 0 ? _a : apolloClient;
272
+ // Generate subscription using the imported 'generate' function
273
+ const { query: subscriptionString, variables: generatedVariables, varCounter } = (0, react_1.useMemo)(() => (0, generator_1.default)(Object.assign({ operation: 'subscription' }, generateOptions)), [generateOptions]);
274
+ // Ensure gql receives a string
275
+ const subscription = (0, react_1.useMemo)(() => (0, client_1.gql) `${subscriptionString}`, [subscriptionString]);
276
+ // Combine variables from generator and hook options (hook options override)
277
+ // Cast the combined object to TVariables
278
+ const combinedVariables = Object.assign(Object.assign({}, generatedVariables), hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.variables);
279
+ // Prepare arguments for the actual Apollo hook
280
+ const { context, apolloOptions } = prepareHookArgs(hookOptions, false);
281
+ const operationName = ((_b = subscription.definitions[0]) === null || _b === void 0 ? void 0 : _b.kind) === 'OperationDefinition' ? ((_c = subscription.definitions[0].name) === null || _c === void 0 ? void 0 : _c.value) || 'UnnamedSub' : 'UnnamedSub';
282
+ // Note: WebSocketLink in apollo.tsx might not support dynamic context/role per subscription easily.
283
+ // The role set via context here primarily affects the initial HTTP request if applicable,
284
+ // or needs custom WebSocket handling if role must change mid-subscription.
285
+ debug(`Executing subscription ${operationName}`, { query: subscriptionString, variables: combinedVariables, context, options: apolloOptions });
286
+ // Explicitly cast apolloOptions to the correct type expected by useApolloSubscription
287
+ const typedApolloOptions = apolloOptions;
288
+ const result = (0, client_2.useSubscription)(subscription, Object.assign({ client, variables: combinedVariables, context }, (typedApolloOptions)));
289
+ debug(`Subscription ${operationName} result`, { loading: result.loading, error: result.error, data: !!result.data });
290
+ return result;
291
+ }
292
+ function useMutation(
293
+ // First arg: Generator options (MUST include operation: 'insert' | 'update' | 'delete')
294
+ generateOptions, // Use full GenerateOptions for mutations
295
+ // Second arg: Hook options (Apollo options + role)
296
+ hookOptions) {
297
+ var _a, _b, _c;
298
+ const apolloClient = (0, client_2.useApolloClient)(); // Use client from context
299
+ const client = (_a = hookOptions === null || hookOptions === void 0 ? void 0 : hookOptions.client) !== null && _a !== void 0 ? _a : apolloClient;
300
+ // Validate that operation is insert/update/delete
301
+ if (!['insert', 'update', 'delete'].includes(generateOptions.operation)) {
302
+ throw new Error(`useMutation hook requires operation to be 'insert', 'update', or 'delete' in generateOptions.`);
303
+ }
304
+ // Generate mutation using the imported 'generate' function
305
+ // Variables from generateOptions are the *base* for the mutation
306
+ const { query: mutationString, variables: baseVariables, varCounter } = (0, react_1.useMemo)(() => (0, generator_1.default)(generateOptions), [generateOptions]);
307
+ // Ensure gql receives a string
308
+ const mutation = (0, react_1.useMemo)(() => (0, client_1.gql) `${mutationString}`, [mutationString]);
309
+ // Prepare arguments for the actual Apollo hook (context, apolloOptions)
310
+ // Variables are NOT prepared here, they are passed to the mutate function
311
+ const { context, apolloOptions } = prepareHookArgs(hookOptions, true); // Pass true for isMutation
312
+ const operationName = ((_b = mutation.definitions[0]) === null || _b === void 0 ? void 0 : _b.kind) === 'OperationDefinition' ? ((_c = mutation.definitions[0].name) === null || _c === void 0 ? void 0 : _c.value) || 'UnnamedMutation' : 'UnnamedMutation';
313
+ debug(`Preparing mutation ${operationName}`, { query: mutationString, context, options: apolloOptions, baseVariables });
314
+ // Explicitly cast apolloOptions to the correct type expected by useApolloMutation
315
+ const typedApolloOptions = apolloOptions;
316
+ // Variables are passed to the mutate function, not the hook itself usually
317
+ const [mutate, result] = (0, client_2.useMutation)(mutation, Object.assign({ client, // Pass the client explicitly if needed
318
+ context }, (typedApolloOptions)));
319
+ // Wrap the mutate function to potentially add logging or other logic
320
+ const wrappedMutate = (0, react_1.useCallback)((mutateOptions) => __awaiter(this, void 0, void 0, function* () {
321
+ // Combine base variables from generator with variables passed to this specific mutate call
322
+ // Cast the combined object to TVariables
323
+ const finalVariables = Object.assign(Object.assign({}, baseVariables), mutateOptions === null || mutateOptions === void 0 ? void 0 : mutateOptions.variables);
324
+ debug(`Executing mutation ${operationName}`, {
325
+ variables: finalVariables,
326
+ context: (mutateOptions === null || mutateOptions === void 0 ? void 0 : mutateOptions.context) || context, // Use context from mutate call or default
327
+ optimisticResponse: mutateOptions === null || mutateOptions === void 0 ? void 0 : mutateOptions.optimisticResponse,
328
+ update: !!(mutateOptions === null || mutateOptions === void 0 ? void 0 : mutateOptions.update),
329
+ });
330
+ try {
331
+ // Pass final combined variables to the actual mutate function
332
+ const mutationResult = yield mutate(Object.assign(Object.assign({}, mutateOptions), { variables: finalVariables }));
333
+ debug(`Mutation ${operationName} success`, { data: mutationResult.data });
334
+ return mutationResult;
335
+ }
336
+ catch (error) {
337
+ debug(`Mutation ${operationName} error`, { error });
338
+ // Let the error propagate to be handled by Apollo Client / component
339
+ throw error;
340
+ }
341
+ }), [mutate, operationName, context, baseVariables]); // Include baseVariables in dependency array
342
+ debug(`Mutation ${operationName} hook state`, { loading: result.loading, error: result.error, data: result.data });
343
+ return [wrappedMutate, result];
344
+ }
345
+ // Aliases for convenience (Hooks)
346
+ exports.useSelect = useQuery;
347
+ const useInsert = (genOpts, hookOpts) => useMutation(Object.assign({ operation: 'insert' }, genOpts), hookOpts);
348
+ exports.useInsert = useInsert;
349
+ const useUpdate = (genOpts, hookOpts) => useMutation(Object.assign({ operation: 'update' }, genOpts), hookOpts);
350
+ exports.useUpdate = useUpdate;
351
+ const useDelete = (genOpts, hookOpts) => useMutation(Object.assign({ operation: 'delete' }, genOpts), hookOpts);
352
+ exports.useDelete = useDelete;
353
+ exports.useSubscribe = useSubscription;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Sends the verification email to a newly registered user.
3
+ * @param email - The recipient's email address.
4
+ * @param token - The verification token.
5
+ * @returns Promise<boolean> - True if email was sent successfully.
6
+ */
7
+ export declare function sendVerificationEmail(email: string, token: string): Promise<boolean>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.sendVerificationEmail = sendVerificationEmail;
16
+ const resend_1 = require("resend");
17
+ const debug_1 = __importDefault(require("@/lib/debug"));
18
+ const debug = (0, debug_1.default)('email');
19
+ const resendApiKey = process.env.RESEND_API_KEY;
20
+ const nextAuthUrl = process.env.NEXTAUTH_URL; // Base URL for verification links
21
+ if (!resendApiKey) {
22
+ console.warn('⚠️ RESEND_API_KEY environment variable is not set. Email sending will be disabled.');
23
+ debug('Resend API key not found.');
24
+ }
25
+ if (!nextAuthUrl) {
26
+ console.warn('⚠️ NEXTAUTH_URL environment variable is not set. Verification links might be incorrect.');
27
+ debug('NEXTAUTH_URL not found.');
28
+ }
29
+ const resend = resendApiKey ? new resend_1.Resend(resendApiKey) : null;
30
+ /**
31
+ * Sends an email using Resend.
32
+ * @param options - Email options (to, subject, html, from).
33
+ * @returns Promise<boolean> - True if email was sent successfully (or Resend is disabled), false otherwise.
34
+ */
35
+ function sendEmail(options) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (!resend) {
38
+ debug('Resend is not configured (missing API key). Skipping email send to: %s', options.to);
39
+ // In development or if key is missing, maybe we pretend it succeeded?
40
+ // Or return false to indicate it wasn't actually sent. Let's return true for now.
41
+ return true;
42
+ }
43
+ const { to, subject, html, from = 'onboarding@resend.dev' } = options; // Default 'from' address
44
+ debug('Attempting to send email via Resend to: %s Subject: %s', to, subject);
45
+ try {
46
+ const { data, error } = yield resend.emails.send({
47
+ from: from,
48
+ to: to,
49
+ subject: subject,
50
+ html: html,
51
+ });
52
+ if (error) {
53
+ debug('Error sending email via Resend:', error);
54
+ console.error("Resend API Error:", error);
55
+ return false;
56
+ }
57
+ debug('Email sent successfully via Resend. ID: %s', data === null || data === void 0 ? void 0 : data.id);
58
+ return true;
59
+ }
60
+ catch (error) {
61
+ debug('Failed to send email due to exception:', error);
62
+ console.error("Exception during email send:", error);
63
+ return false;
64
+ }
65
+ });
66
+ }
67
+ /**
68
+ * Sends the verification email to a newly registered user.
69
+ * @param email - The recipient's email address.
70
+ * @param token - The verification token.
71
+ * @returns Promise<boolean> - True if email was sent successfully.
72
+ */
73
+ function sendVerificationEmail(email, token) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const verificationLink = `${nextAuthUrl || 'http://localhost:3000'}/api/auth/verify?token=${token}`;
76
+ debug('Generated verification link: %s', verificationLink);
77
+ const subject = 'Verify your email address';
78
+ const html = `<p>Welcome! Please click the link below to verify your email address:</p>
79
+ <p><a href="${verificationLink}">Verify Email</a></p>
80
+ <p>If you didn't request this, please ignore this email.</p>
81
+ <p>Link: ${verificationLink}</p>`; // Include link as text too
82
+ return sendEmail({
83
+ to: email,
84
+ subject: subject,
85
+ html: html,
86
+ // You might want to customize the 'from' address later
87
+ // from: 'Your App Name <verify@yourdomain.com>'
88
+ });
89
+ });
90
+ }
@@ -0,0 +1,6 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import http from 'http';
3
+ import { WebSocket, WebSocketServer } from 'ws';
4
+ export declare function proxyGET(request: NextRequest): Promise<NextResponse>;
5
+ export declare function proxyPOST(request: NextRequest): Promise<NextResponse>;
6
+ export declare function proxySOCKET(client: WebSocket, request: http.IncomingMessage, server: WebSocketServer): Promise<void>;