How to Implement User Verification
This guide demonstrates how to implement user verification end-to-end using a simply Node.js Express server.
Last updated
Was this helpful?
Was this helpful?
mkdir released-auth-demo
cd released-auth-demo
npm init -y
npm install expressconst express = require('express');
const app = express();
const port = 3000;
// --- CONFIGURATION ---
// TODO: Replace with your actual values from Released Settings
const CONFIG = {
SHARED_SECRET: 'YOUR_SHARED_SECRET',
ACCOUNT_ID: 'YOUR_ACCOUNT_ID',
CHANNEL_ID: 'YOUR_CHANNEL_ID'
};
// --- MOCK USER DATA ---
// In your real app, this comes from your database or session
const currentUser = {
id: "user_12345",
email: "[email protected]",
name: "John Doe",
avatar: "https://ui-avatars.com/api/?name=John+Doe"
};
// --- THE ROUTE ---
app.get('/', async (req, res) => {
try {
// 1. Generate the Auth Token server-side
// We send the current user's details to Released to get a temporary token
const response = await fetch("https://accounts.releasedhub.com/auth/api/impersonation/token", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${CONFIG.SHARED_SECRET}`
},
body: JSON.stringify({
account_id: CONFIG.ACCOUNT_ID,
user_id: currentUser.id,
user_email: currentUser.email,
profile: {
name: currentUser.name,
avatar_url: currentUser.avatar
}
}),
});
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
const data = await response.json();
const token = data; // The short-lived JWT
// 2. Serve the HTML with the token injected
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Released Verification Example</title>
<script type="module" src="https://embed.released.so/released-embed.js"></script>
</head>
<body style="font-family: sans-serif; padding: 40px;">
<h1>Hello, ${currentUser.name}</h1>
<p>This roadmap is authenticated specifically for you.</p>
<hr />
<released-page
channel-id="${CONFIG.CHANNEL_ID}"
auth-token="${token}">
</released-page>
</body>
</html>
`);
} catch (error) {
console.error(error);
res.status(500).send("Error generating token. Check server console.");
}
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});node server.jsngrok http 3000