nextjs-hasura-auth 0.1.1 → 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.
- package/APOLLO.md +101 -174
- package/GENERATOR.md +4 -5
- package/README.md +9 -5
- package/dist/lib/apollo.d.ts +11 -9
- package/dist/lib/apollo.js +127 -90
- package/dist/lib/auth.d.ts +16 -0
- package/dist/lib/auth.js +159 -0
- package/dist/lib/authDbUtils.d.ts +48 -0
- package/dist/lib/authDbUtils.js +183 -0
- package/dist/lib/client.d.ts +81 -0
- package/dist/lib/client.js +353 -0
- package/dist/lib/email.d.ts +7 -0
- package/dist/lib/email.js +90 -0
- package/dist/lib/generator.d.ts +2 -7
- package/dist/lib/generator.js +394 -392
- package/dist/lib/graphql-proxy.d.ts +6 -0
- package/dist/lib/graphql-proxy.js +385 -0
- package/dist/lib/hasura-schema.d.ts +1 -0
- package/dist/lib/hasura-schema.js +65 -0
- package/dist/lib/hasura.d.ts +16 -0
- package/dist/lib/hasura.js +102 -0
- package/dist/lib/hooks/useCheckConnection.d.ts +7 -0
- package/dist/lib/hooks/useCheckConnection.js +62 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.js +5 -0
- package/dist/lib/test-utils.d.ts +11 -0
- package/dist/lib/test-utils.js +59 -0
- package/dist/lib/tokenUtils.d.ts +14 -0
- package/dist/lib/tokenUtils.js +94 -0
- package/dist/package.json +22 -4
- package/dist/public/hasura-schema.json +7995 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -6
@@ -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
|
+
}
|
package/dist/lib/generator.d.ts
CHANGED
@@ -23,11 +23,6 @@ export interface GenerateResult {
|
|
23
23
|
variables: Record<string, any>;
|
24
24
|
varCounter: number;
|
25
25
|
}
|
26
|
-
/**
|
27
|
-
* Creates a GraphQL query generator based on the provided schema.
|
28
|
-
*
|
29
|
-
* @param schema - The GraphQL schema in schema.json format.
|
30
|
-
* @returns A function to generate queries.
|
31
|
-
*/
|
32
26
|
export declare function Generator(schema: any): (opts: GenerateOptions) => GenerateResult;
|
33
|
-
|
27
|
+
declare const _default: (opts: GenerateOptions) => GenerateResult;
|
28
|
+
export default _default;
|