alpha testing feature flag
This commit is contained in:
@@ -7,6 +7,11 @@ const logger = require("../utils/logger");
|
||||
*/
|
||||
const requireAlphaAccess = async (req, res, next) => {
|
||||
try {
|
||||
// Bypass alpha access check if feature is disabled
|
||||
if (process.env.ALPHA_TESTING_ENABLED !== 'true') {
|
||||
return next();
|
||||
}
|
||||
|
||||
let hasAccess = false;
|
||||
|
||||
// Check 1: Valid alpha access cookie
|
||||
|
||||
@@ -8,6 +8,11 @@ const router = express.Router();
|
||||
|
||||
// Helper function to check if user has alpha access
|
||||
async function checkAlphaAccess(req) {
|
||||
// Bypass alpha access check if feature is disabled
|
||||
if (process.env.ALPHA_TESTING_ENABLED !== 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check 1: Valid alpha access cookie
|
||||
if (req.cookies && req.cookies.alphaAccessCode) {
|
||||
const { code } = req.cookies.alphaAccessCode;
|
||||
|
||||
@@ -66,31 +66,33 @@ router.post(
|
||||
|
||||
// Alpha access validation
|
||||
let alphaInvitation = null;
|
||||
if (req.signedCookies && req.signedCookies.alphaAccessCode) {
|
||||
const { code } = req.signedCookies.alphaAccessCode;
|
||||
if (code) {
|
||||
alphaInvitation = await AlphaInvitation.findOne({
|
||||
where: { code },
|
||||
});
|
||||
|
||||
if (!alphaInvitation) {
|
||||
return res.status(403).json({
|
||||
error: "Invalid alpha access code",
|
||||
if (process.env.ALPHA_TESTING_ENABLED === 'true') {
|
||||
if (req.cookies && req.cookies.alphaAccessCode) {
|
||||
const { code } = req.cookies.alphaAccessCode;
|
||||
if (code) {
|
||||
alphaInvitation = await AlphaInvitation.findOne({
|
||||
where: { code },
|
||||
});
|
||||
}
|
||||
|
||||
if (alphaInvitation.status === "revoked") {
|
||||
return res.status(403).json({
|
||||
error: "This alpha access code is no longer valid",
|
||||
});
|
||||
if (!alphaInvitation) {
|
||||
return res.status(403).json({
|
||||
error: "Invalid alpha access code",
|
||||
});
|
||||
}
|
||||
|
||||
if (alphaInvitation.status === "revoked") {
|
||||
return res.status(403).json({
|
||||
error: "This alpha access code is no longer valid",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!alphaInvitation) {
|
||||
return res.status(403).json({
|
||||
error: "Alpha access required. Please enter your invitation code first.",
|
||||
});
|
||||
if (!alphaInvitation) {
|
||||
return res.status(403).json({
|
||||
error: "Alpha access required. Please enter your invitation code first.",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const user = await User.create({
|
||||
@@ -356,17 +358,19 @@ router.post(
|
||||
});
|
||||
|
||||
// Check if there's an alpha invitation for this email
|
||||
const alphaInvitation = await AlphaInvitation.findOne({
|
||||
where: { email: email.toLowerCase().trim() },
|
||||
});
|
||||
|
||||
if (alphaInvitation && !alphaInvitation.usedBy) {
|
||||
// Link invitation to new user
|
||||
await alphaInvitation.update({
|
||||
usedBy: user.id,
|
||||
usedAt: new Date(),
|
||||
status: "active",
|
||||
if (process.env.ALPHA_TESTING_ENABLED === 'true') {
|
||||
const alphaInvitation = await AlphaInvitation.findOne({
|
||||
where: { email: email.toLowerCase().trim() },
|
||||
});
|
||||
|
||||
if (alphaInvitation && !alphaInvitation.usedBy) {
|
||||
// Link invitation to new user
|
||||
await alphaInvitation.update({
|
||||
usedBy: user.id,
|
||||
usedAt: new Date(),
|
||||
status: "active",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user