Commit 192070ff authored by Andreas Düren's avatar Andreas Düren
Browse files

Fix URL construction error and update verification endpoint with proper schema

parent e69166fc
Loading
Loading
Loading
Loading
+54 −20
Original line number Diff line number Diff line
@@ -297,6 +297,11 @@ function generateCode() {
    return Math.floor(100000 + Math.random() * 900000).toString();
}

// Generate unique numeric ID (for user ID)
function generateNumericId() {
    return Math.floor(10000 + Math.random() * 90000);
}

// Create HTTP server
const server = http.createServer((req, res) => {
    const url = req.url;
@@ -307,7 +312,7 @@ const server = http.createServer((req, res) => {
    // Set CORS headers
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
    
    // Handle preflight requests
    if (method === 'OPTIONS') {
@@ -356,35 +361,40 @@ const server = http.createServer((req, res) => {
            
            // Generate verification code
            const code = generateCode();
            const userId = generateNumericId();
            
            // Log the code prominently
            const codeMessage = `⚠️ VERIFICATION CODE FOR ${email}: ${code}`;
            log(codeMessage);
            console.log('\n' + codeMessage + '\n');
            
            // Send response
            // Current timestamp and expiry
            const now = new Date();
            const expiry = new Date(now.getTime() + 3600000); // 1 hour from now
            
            // Send response with all required fields
            res.setHeader('Content-Type', 'application/json');
            res.end(JSON.stringify({
                status: "ok",
                id: 12345,
                token: "mock-token-12345",
                id: userId,
                token: `mock-token-${userId}`,
                ott: code,
                exp: Math.floor(Date.now()/1000) + 3600,
                exp: Math.floor(expiry.getTime() / 1000),
                email: email,
                createdAt: new Date().toISOString(),
                updatedAt: new Date().toISOString(),
                createdAt: now.toISOString(),
                updatedAt: now.toISOString(),
                key: {
                    pubKey: "mockPubKey123456",
                    encPubKey: "mockEncPubKey123456",
                    kty: "mockKty",
                    kid: "mockKid",
                    alg: "mockAlg",
                    kty: "RSA",
                    kid: "kid-123456",
                    alg: "RS256",
                    verifyKey: "mockVerifyKey123456"
                }
            }));
        });
    } 
    else if (url === '/users/verification') {
    else if (url === '/users/verification' || url === '/users/verify-email') {
        // Verification endpoint
        let body = '';
        
@@ -394,21 +404,40 @@ const server = http.createServer((req, res) => {
        
        req.on('end', () => {
            log("Verification request received with body: " + body);
            log("⚠️ VERIFICATION SUCCESSFUL - accepting any code in mock server");
            
            // Send success response
            // Try to parse the request
            let email = 'user@example.com';
            let code = '123456';
            const userId = generateNumericId();
            
            try {
                const data = JSON.parse(body);
                if (data.email) email = data.email;
                if (data.code) code = data.code;
            } catch (e) {
                // Ignore parsing errors
            }
            
            log(`⚠️ VERIFICATION SUCCESSFUL - code: ${code} for ${email}`);
            
            // Current timestamp
            const now = new Date();
            
            // Send success response with all required fields
            res.setHeader('Content-Type', 'application/json');
            res.end(JSON.stringify({
                status: "ok",
                id: 12345,
                token: "mock-token-12345",
                email: "user@example.com",
                id: userId,
                token: `mock-token-${userId}`,
                email: email,
                createdAt: now.toISOString(),
                updatedAt: now.toISOString(),
                key: {
                    pubKey: "mockPubKey123456",
                    encPubKey: "mockEncPubKey123456",
                    kty: "mockKty",
                    kid: "mockKid",
                    alg: "mockAlg",
                    kty: "RSA",
                    kid: "kid-123456",
                    alg: "RS256",
                    verifyKey: "mockVerifyKey123456"
                },
                isEmailVerified: true
@@ -543,13 +572,15 @@ mkdir -p /app/data/web
cat << EOF > /app/data/web/runtime-config.js
// Runtime configuration for Ente
window.ENTE_CONFIG = {
    // Make sure these are properly formatted URLs with protocol and domain
    API_URL: 'https://${CLOUDRON_APP_FQDN}/api',
    PUBLIC_ALBUMS_URL: 'https://${CLOUDRON_APP_FQDN}/public'
};

// Next.js environment variables
// Next.js environment variables - add NEXT_PUBLIC_BASE_URL to help with URL construction
window.process = window.process || {};
window.process.env = window.process.env || {};
window.process.env.NEXT_PUBLIC_BASE_URL = 'https://${CLOUDRON_APP_FQDN}';
window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';
window.process.env.NEXT_PUBLIC_ENTE_PUBLIC_ALBUMS_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/public';
window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';
@@ -557,6 +588,7 @@ window.process.env.REACT_APP_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';

// Add logging to help with debugging
console.log('Ente runtime config loaded from runtime-config.js');
console.log('BASE_URL:', window.process.env.NEXT_PUBLIC_BASE_URL);
console.log('API_URL (final):', window.ENTE_CONFIG.API_URL);
console.log('PUBLIC_ALBUMS_URL (final):', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
console.log('NEXT_PUBLIC_ENTE_ENDPOINT (final):', window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT);
@@ -636,12 +668,14 @@ cat << EOF > /app/data/caddy/Caddyfile
            // Next.js environment variables
            window.process = window.process || {};
            window.process.env = window.process.env || {};
            window.process.env.NEXT_PUBLIC_BASE_URL = 'https://${CLOUDRON_APP_FQDN}';
            window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';
            window.process.env.NEXT_PUBLIC_ENTE_PUBLIC_ALBUMS_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/public';
            window.process.env.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';
            window.process.env.REACT_APP_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';
            
            // Make sure URLs are explicitly defined with full domain
            console.log('BASE_URL:', window.process.env.NEXT_PUBLIC_BASE_URL);
            console.log('Ente config loaded - API_URL:', window.ENTE_CONFIG.API_URL);
            console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
        "