@mindfulauth/core 3.0.0 → 3.0.1
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/package.json +2 -2
- package/dist/astro/ForgotPasswordScript.astro +0 -64
- package/dist/astro/LoginScript.astro +0 -209
- package/dist/astro/MagicLoginScript.astro +0 -62
- package/dist/astro/MagicRegisterScript.astro +0 -73
- package/dist/astro/MainScript.astro +0 -236
- package/dist/astro/RegisterPasswordScript.astro +0 -118
- package/dist/astro/ResendVerificationScript.astro +0 -51
- package/dist/astro/ResetPasswordScript.astro +0 -155
- package/dist/astro/SecurityScript.astro +0 -449
- package/dist/astro/TurnstileInit.astro +0 -112
- package/dist/astro/VerifyEmailScript.astro +0 -72
- package/dist/astro/VerifyMagicLinkScript.astro +0 -195
- package/dist/astro/index.d.ts +0 -13
- package/dist/astro/index.d.ts.map +0 -1
- package/dist/astro/index.js +0 -15
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
// Mindful Auth - Verify Magic Link Script Component
|
|
3
|
-
// Provides: Magic link verification with 2FA support
|
|
4
|
-
---
|
|
5
|
-
<script is:inline>
|
|
6
|
-
// Verify Magic Link Script - Astro Optimized
|
|
7
|
-
|
|
8
|
-
function getPathParams() {
|
|
9
|
-
const pathParts = window.location.pathname.split('/');
|
|
10
|
-
return {
|
|
11
|
-
recordid: pathParts[2],
|
|
12
|
-
token: pathParts[3]
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function handleVerifyMagicLinkSubmit(event) {
|
|
17
|
-
if (event) event.preventDefault();
|
|
18
|
-
|
|
19
|
-
const form = document.querySelector('[data-mindfulauth-form="verify-magic-link"]');
|
|
20
|
-
if (!form) return;
|
|
21
|
-
const messageEl = document.querySelector('[data-mindfulauth-field="message"]');
|
|
22
|
-
if (!messageEl) return;
|
|
23
|
-
const twoFACodeEl = form.querySelector('[data-mindfulauth-field="twofa-code"]');
|
|
24
|
-
const submitBtn = form.querySelector('button[type="submit"]');
|
|
25
|
-
|
|
26
|
-
// Skip API call on localhost to prevent production logs pollution
|
|
27
|
-
const hostname = window.location.hostname;
|
|
28
|
-
if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname.endsWith('.local')) {
|
|
29
|
-
messageEl.textContent = 'Magic link verification skipped on localhost.';
|
|
30
|
-
console.log('[Verify Magic Link] Skipping API call on localhost');
|
|
31
|
-
if (form) form.style.display = 'none';
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { recordid, token } = getPathParams();
|
|
36
|
-
|
|
37
|
-
if (!recordid || !token) {
|
|
38
|
-
messageEl.textContent = "Invalid or expired magic link. Please request a new one.";
|
|
39
|
-
if (form) form.style.display = 'none';
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Get Turnstile token
|
|
44
|
-
const turnstileToken = form.querySelector('[name="cf-turnstile-response"]')?.value;
|
|
45
|
-
if (!turnstileToken) {
|
|
46
|
-
messageEl.textContent = "Bot protection validation required.";
|
|
47
|
-
if (submitBtn) submitBtn.disabled = true;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
messageEl.textContent = "Verifying magic link...";
|
|
52
|
-
if (submitBtn) submitBtn.disabled = true;
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const requestBody = {
|
|
56
|
-
'cf-turnstile-response': turnstileToken
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Include 2FA code if provided
|
|
60
|
-
if (twoFACodeEl && twoFACodeEl.value) {
|
|
61
|
-
requestBody.twoFACode = twoFACodeEl.value;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const endpoint = `/auth/verify-magic-link/${recordid}/${token}`;
|
|
65
|
-
console.log('[Verify Magic Link] Making request to:', endpoint);
|
|
66
|
-
console.log('[Verify Magic Link] Request body:', requestBody);
|
|
67
|
-
|
|
68
|
-
const response = await window.apiFetch(endpoint, {
|
|
69
|
-
body: JSON.stringify(requestBody)
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
console.log('[Verify Magic Link] Response status:', response.status);
|
|
73
|
-
const result = await response.json();
|
|
74
|
-
console.log('[Verify Magic Link] Response body:', result);
|
|
75
|
-
|
|
76
|
-
// Check if 2FA is required
|
|
77
|
-
if (result.requires2FA) {
|
|
78
|
-
// Reset Turnstile to generate a fresh token for the 2FA submission
|
|
79
|
-
// (Turnstile tokens are single-use; first request consumed it)
|
|
80
|
-
window.turnstile?.reset();
|
|
81
|
-
|
|
82
|
-
// Show the 2FA input field
|
|
83
|
-
const twoFAContainer = form.querySelector('[data-mindfulauth-field="twofa-code-container"]');
|
|
84
|
-
if (twoFAContainer) {
|
|
85
|
-
twoFAContainer.removeAttribute('hidden');
|
|
86
|
-
twoFAContainer.classList && twoFAContainer.classList.remove('hidden');
|
|
87
|
-
twoFAContainer.style.setProperty('display', 'block', 'important');
|
|
88
|
-
// Try common display values
|
|
89
|
-
if (window.getComputedStyle(twoFAContainer).display === 'none') {
|
|
90
|
-
twoFAContainer.style.setProperty('display', 'flex', 'important');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (twoFACodeEl) {
|
|
94
|
-
twoFACodeEl.focus();
|
|
95
|
-
}
|
|
96
|
-
messageEl.textContent = '2FA code is required to complete login.';
|
|
97
|
-
if (submitBtn) {
|
|
98
|
-
submitBtn.textContent = 'Verify 2FA Code';
|
|
99
|
-
submitBtn.disabled = false;
|
|
100
|
-
}
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (result.success) {
|
|
105
|
-
console.log('[Verify Magic Link] Verification successful');
|
|
106
|
-
messageEl.textContent = result.message || 'Login successful! Redirecting...';
|
|
107
|
-
if (form) form.style.display = 'none';
|
|
108
|
-
|
|
109
|
-
// Redirect to secure area (match login.js pattern)
|
|
110
|
-
if (result.redirect) {
|
|
111
|
-
console.log('[Verify Magic Link] Redirecting to:', result.redirect);
|
|
112
|
-
setTimeout(() => {
|
|
113
|
-
window.location.assign(result.redirect);
|
|
114
|
-
}, 200);
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
console.error('[Verify Magic Link] Verification failed:', result.message);
|
|
118
|
-
throw new Error(result.message || 'Verification failed.');
|
|
119
|
-
}
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error('[Verify Magic Link] Error:', error);
|
|
122
|
-
messageEl.textContent = `Error: ${error.message}`;
|
|
123
|
-
if (submitBtn) submitBtn.disabled = false;
|
|
124
|
-
window.turnstile?.reset();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// --- MAIN EXECUTION ---
|
|
129
|
-
document.addEventListener('DOMContentLoaded', function() {
|
|
130
|
-
const form = document.querySelector('[data-mindfulauth-form="verify-magic-link"]');
|
|
131
|
-
if (!form) return;
|
|
132
|
-
|
|
133
|
-
// Initialize message and disable button until Turnstile is ready
|
|
134
|
-
const messageEl = document.querySelector('[data-mindfulauth-field="message"]');
|
|
135
|
-
const submitBtn = form.querySelector('button[type="submit"]');
|
|
136
|
-
if (messageEl) {
|
|
137
|
-
messageEl.textContent = 'Loading bot protection...';
|
|
138
|
-
}
|
|
139
|
-
if (submitBtn) {
|
|
140
|
-
submitBtn.disabled = true;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Initially hide 2FA field - it will be shown if needed
|
|
144
|
-
const twoFAContainer = form.querySelector('[data-mindfulauth-field="twofa-code-container"]');
|
|
145
|
-
if (twoFAContainer) {
|
|
146
|
-
twoFAContainer.style.display = 'none';
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Wait for Turnstile to be ready
|
|
150
|
-
let turnstileReady = false;
|
|
151
|
-
const checkTurnstile = setInterval(() => {
|
|
152
|
-
const turnstileToken = form.querySelector('[name="cf-turnstile-response"]')?.value;
|
|
153
|
-
if (turnstileToken) {
|
|
154
|
-
console.log('[Verify Magic Link] Turnstile token loaded - ready for user verification');
|
|
155
|
-
clearInterval(checkTurnstile);
|
|
156
|
-
turnstileReady = true;
|
|
157
|
-
const messageEl = document.querySelector('[data-mindfulauth-field="message"]');
|
|
158
|
-
if (messageEl) {
|
|
159
|
-
messageEl.textContent = 'Ready to verify. Click the button below to sign in.';
|
|
160
|
-
}
|
|
161
|
-
const submitBtn = form.querySelector('button[type="submit"]');
|
|
162
|
-
if (submitBtn) {
|
|
163
|
-
submitBtn.disabled = false;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}, 100);
|
|
167
|
-
|
|
168
|
-
// Check for Turnstile load every 500ms for up to 30 seconds
|
|
169
|
-
// (don't show error proactively - only if user tries to submit)
|
|
170
|
-
let turnstileCheckCount = 0;
|
|
171
|
-
const extendedCheckTurnstile = setInterval(() => {
|
|
172
|
-
const turnstileToken = form.querySelector('[name="cf-turnstile-response"]')?.value;
|
|
173
|
-
if (turnstileToken && !turnstileReady) {
|
|
174
|
-
clearInterval(extendedCheckTurnstile);
|
|
175
|
-
turnstileReady = true;
|
|
176
|
-
const messageEl = document.querySelector('[data-mindfulauth-field="message"]');
|
|
177
|
-
if (messageEl) {
|
|
178
|
-
messageEl.textContent = 'Ready to verify. Click the button below to sign in.';
|
|
179
|
-
}
|
|
180
|
-
const submitBtn = form.querySelector('button[type="submit"]');
|
|
181
|
-
if (submitBtn) {
|
|
182
|
-
submitBtn.disabled = false;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
turnstileCheckCount++;
|
|
186
|
-
// Stop checking after 30 seconds
|
|
187
|
-
if (turnstileCheckCount > 60) {
|
|
188
|
-
clearInterval(extendedCheckTurnstile);
|
|
189
|
-
}
|
|
190
|
-
}, 500);
|
|
191
|
-
|
|
192
|
-
// Also handle explicit form submission (for 2FA code entry)
|
|
193
|
-
form.addEventListener('submit', handleVerifyMagicLinkSubmit);
|
|
194
|
-
});
|
|
195
|
-
</script>
|
package/dist/astro/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { default as MAuthMainScript } from './MainScript.astro';
|
|
2
|
-
export { default as MAuthTurnstileInit } from './TurnstileInit.astro';
|
|
3
|
-
export { default as MAuthLoginScript } from './LoginScript.astro';
|
|
4
|
-
export { default as MAuthRegisterPasswordScript } from './RegisterPasswordScript.astro';
|
|
5
|
-
export { default as MAuthForgotPasswordScript } from './ForgotPasswordScript.astro';
|
|
6
|
-
export { default as MAuthMagicLoginScript } from './MagicLoginScript.astro';
|
|
7
|
-
export { default as MAuthMagicRegisterScript } from './MagicRegisterScript.astro';
|
|
8
|
-
export { default as MAuthResendVerificationScript } from './ResendVerificationScript.astro';
|
|
9
|
-
export { default as MAuthResetPasswordScript } from './ResetPasswordScript.astro';
|
|
10
|
-
export { default as MAuthVerifyEmailScript } from './VerifyEmailScript.astro';
|
|
11
|
-
export { default as MAuthVerifyMagicLinkScript } from './VerifyMagicLinkScript.astro';
|
|
12
|
-
export { default as MAuthSecurityScript } from './SecurityScript.astro';
|
|
13
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/astro/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AACxF,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,6BAA6B,EAAE,MAAM,kCAAkC,CAAC;AAC5F,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/astro/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Mindful Auth - Astro Components Barrel Export
|
|
2
|
-
// Usage: import { MAuthLoginScript, MAuthTurnstileInit } from '@mindfulauth/astro';
|
|
3
|
-
// or: import MAuthLoginScript from '@mindfulauth/astro/LoginScript.astro';
|
|
4
|
-
export { default as MAuthMainScript } from './MainScript.astro';
|
|
5
|
-
export { default as MAuthTurnstileInit } from './TurnstileInit.astro';
|
|
6
|
-
export { default as MAuthLoginScript } from './LoginScript.astro';
|
|
7
|
-
export { default as MAuthRegisterPasswordScript } from './RegisterPasswordScript.astro';
|
|
8
|
-
export { default as MAuthForgotPasswordScript } from './ForgotPasswordScript.astro';
|
|
9
|
-
export { default as MAuthMagicLoginScript } from './MagicLoginScript.astro';
|
|
10
|
-
export { default as MAuthMagicRegisterScript } from './MagicRegisterScript.astro';
|
|
11
|
-
export { default as MAuthResendVerificationScript } from './ResendVerificationScript.astro';
|
|
12
|
-
export { default as MAuthResetPasswordScript } from './ResetPasswordScript.astro';
|
|
13
|
-
export { default as MAuthVerifyEmailScript } from './VerifyEmailScript.astro';
|
|
14
|
-
export { default as MAuthVerifyMagicLinkScript } from './VerifyMagicLinkScript.astro';
|
|
15
|
-
export { default as MAuthSecurityScript } from './SecurityScript.astro';
|