-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth.js
More file actions
17 lines (15 loc) · 841 Bytes
/
auth.js
File metadata and controls
17 lines (15 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Magic } from 'https://cdn.jsdelivr.net/npm/magic-sdk@latest/dist/magic.js';
const MAGIC_PUBLISHABLE_KEY = "pk_live_8A7A254AFE5756EC"; // replace with your Magic publishable key
// Initialize Magic with Flow extension
const magic = new Magic(MAGIC_PUBLISHABLE_KEY, { extensions: { flow: new Magic.FlowExtension({ rpcUrl: "https://rest-testnet.onflow.org" }) } });
document.getElementById("loginBtn")?.addEventListener("click", async () => {
try {
const accounts = await magic.auth.loginWithEmailOTP({ email: prompt("Enter email:") });
const meta = await magic.user.getMetadata();
document.getElementById("userMeta").textContent = JSON.stringify(meta, null, 2);
localStorage.setItem("magicUser", JSON.stringify(meta));
window.location.href = "dashboard.html";
} catch (err) {
console.error(err);
}
});