@alinsafawi/aegis-auth 0.2.4 → 0.2.5
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/dist/index.js +21 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23616,23 +23616,27 @@ export default function LoginPage() {
|
|
|
23616
23616
|
setError('')
|
|
23617
23617
|
setLoading(true)
|
|
23618
23618
|
|
|
23619
|
-
|
|
23620
|
-
.
|
|
23621
|
-
|
|
23622
|
-
|
|
23623
|
-
|
|
23624
|
-
|
|
23625
|
-
|
|
23626
|
-
|
|
23627
|
-
|
|
23628
|
-
|
|
23629
|
-
|
|
23630
|
-
|
|
23631
|
-
|
|
23632
|
-
|
|
23633
|
-
|
|
23634
|
-
|
|
23635
|
-
|
|
23619
|
+
try {
|
|
23620
|
+
const csrf = document.cookie
|
|
23621
|
+
.split('; ')
|
|
23622
|
+
.find((r) => r.startsWith('${appName.toLowerCase().replace(/[^a-z]/g, "")}_csrf='))
|
|
23623
|
+
?.split('=')[1]
|
|
23624
|
+
|
|
23625
|
+
const res = await fetch('/api/auth/login', {
|
|
23626
|
+
method: 'POST',
|
|
23627
|
+
headers: { 'Content-Type': 'application/json', 'x-csrf-token': csrf ?? '' },
|
|
23628
|
+
body: JSON.stringify({ identifier, password }),
|
|
23629
|
+
})
|
|
23630
|
+
|
|
23631
|
+
const data = await res.json()
|
|
23632
|
+
if (!res.ok) { setError(data.error ?? 'Login failed'); return }
|
|
23633
|
+
if (data.requiresTwoFactor) { router.push('/two-factor'); return }
|
|
23634
|
+
router.push(\`/\${data.role}/dashboard\`)
|
|
23635
|
+
} catch {
|
|
23636
|
+
setError('Network error \u2014 please try again.')
|
|
23637
|
+
} finally {
|
|
23638
|
+
setLoading(false)
|
|
23639
|
+
}
|
|
23636
23640
|
}
|
|
23637
23641
|
|
|
23638
23642
|
return (
|