Fix URL construction error and update verification endpoint with proper schema
This commit is contained in:
		
							
								
								
									
										74
									
								
								start.sh
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								start.sh
									
									
									
									
									
								
							@@ -297,6 +297,11 @@ function generateCode() {
 | 
				
			|||||||
    return Math.floor(100000 + Math.random() * 900000).toString();
 | 
					    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
 | 
					// Create HTTP server
 | 
				
			||||||
const server = http.createServer((req, res) => {
 | 
					const server = http.createServer((req, res) => {
 | 
				
			||||||
    const url = req.url;
 | 
					    const url = req.url;
 | 
				
			||||||
@@ -307,7 +312,7 @@ const server = http.createServer((req, res) => {
 | 
				
			|||||||
    // Set CORS headers
 | 
					    // Set CORS headers
 | 
				
			||||||
    res.setHeader('Access-Control-Allow-Origin', '*');
 | 
					    res.setHeader('Access-Control-Allow-Origin', '*');
 | 
				
			||||||
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
 | 
					    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
 | 
					    // Handle preflight requests
 | 
				
			||||||
    if (method === 'OPTIONS') {
 | 
					    if (method === 'OPTIONS') {
 | 
				
			||||||
@@ -356,35 +361,40 @@ const server = http.createServer((req, res) => {
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
            // Generate verification code
 | 
					            // Generate verification code
 | 
				
			||||||
            const code = generateCode();
 | 
					            const code = generateCode();
 | 
				
			||||||
 | 
					            const userId = generateNumericId();
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            // Log the code prominently
 | 
					            // Log the code prominently
 | 
				
			||||||
            const codeMessage = `⚠️ VERIFICATION CODE FOR ${email}: ${code}`;
 | 
					            const codeMessage = `⚠️ VERIFICATION CODE FOR ${email}: ${code}`;
 | 
				
			||||||
            log(codeMessage);
 | 
					            log(codeMessage);
 | 
				
			||||||
            console.log('\n' + codeMessage + '\n');
 | 
					            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.setHeader('Content-Type', 'application/json');
 | 
				
			||||||
            res.end(JSON.stringify({
 | 
					            res.end(JSON.stringify({
 | 
				
			||||||
                status: "ok",
 | 
					                status: "ok",
 | 
				
			||||||
                id: 12345,
 | 
					                id: userId,
 | 
				
			||||||
                token: "mock-token-12345",
 | 
					                token: `mock-token-${userId}`,
 | 
				
			||||||
                ott: code,
 | 
					                ott: code,
 | 
				
			||||||
                exp: Math.floor(Date.now()/1000) + 3600,
 | 
					                exp: Math.floor(expiry.getTime() / 1000),
 | 
				
			||||||
                email: email,
 | 
					                email: email,
 | 
				
			||||||
                createdAt: new Date().toISOString(),
 | 
					                createdAt: now.toISOString(),
 | 
				
			||||||
                updatedAt: new Date().toISOString(),
 | 
					                updatedAt: now.toISOString(),
 | 
				
			||||||
                key: {
 | 
					                key: {
 | 
				
			||||||
                    pubKey: "mockPubKey123456",
 | 
					                    pubKey: "mockPubKey123456",
 | 
				
			||||||
                    encPubKey: "mockEncPubKey123456",
 | 
					                    encPubKey: "mockEncPubKey123456",
 | 
				
			||||||
                    kty: "mockKty",
 | 
					                    kty: "RSA",
 | 
				
			||||||
                    kid: "mockKid",
 | 
					                    kid: "kid-123456",
 | 
				
			||||||
                    alg: "mockAlg",
 | 
					                    alg: "RS256",
 | 
				
			||||||
                    verifyKey: "mockVerifyKey123456"
 | 
					                    verifyKey: "mockVerifyKey123456"
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }));
 | 
					            }));
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    } 
 | 
					    } 
 | 
				
			||||||
    else if (url === '/users/verification') {
 | 
					    else if (url === '/users/verification' || url === '/users/verify-email') {
 | 
				
			||||||
        // Verification endpoint
 | 
					        // Verification endpoint
 | 
				
			||||||
        let body = '';
 | 
					        let body = '';
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@@ -394,21 +404,40 @@ const server = http.createServer((req, res) => {
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        req.on('end', () => {
 | 
					        req.on('end', () => {
 | 
				
			||||||
            log("Verification request received with body: " + body);
 | 
					            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.setHeader('Content-Type', 'application/json');
 | 
				
			||||||
            res.end(JSON.stringify({
 | 
					            res.end(JSON.stringify({
 | 
				
			||||||
                status: "ok",
 | 
					                status: "ok",
 | 
				
			||||||
                id: 12345,
 | 
					                id: userId,
 | 
				
			||||||
                token: "mock-token-12345",
 | 
					                token: `mock-token-${userId}`,
 | 
				
			||||||
                email: "user@example.com",
 | 
					                email: email,
 | 
				
			||||||
 | 
					                createdAt: now.toISOString(),
 | 
				
			||||||
 | 
					                updatedAt: now.toISOString(),
 | 
				
			||||||
                key: {
 | 
					                key: {
 | 
				
			||||||
                    pubKey: "mockPubKey123456",
 | 
					                    pubKey: "mockPubKey123456",
 | 
				
			||||||
                    encPubKey: "mockEncPubKey123456",
 | 
					                    encPubKey: "mockEncPubKey123456",
 | 
				
			||||||
                    kty: "mockKty",
 | 
					                    kty: "RSA",
 | 
				
			||||||
                    kid: "mockKid",
 | 
					                    kid: "kid-123456",
 | 
				
			||||||
                    alg: "mockAlg",
 | 
					                    alg: "RS256",
 | 
				
			||||||
                    verifyKey: "mockVerifyKey123456"
 | 
					                    verifyKey: "mockVerifyKey123456"
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                isEmailVerified: true
 | 
					                isEmailVerified: true
 | 
				
			||||||
@@ -543,13 +572,15 @@ mkdir -p /app/data/web
 | 
				
			|||||||
cat << EOF > /app/data/web/runtime-config.js
 | 
					cat << EOF > /app/data/web/runtime-config.js
 | 
				
			||||||
// Runtime configuration for Ente
 | 
					// Runtime configuration for Ente
 | 
				
			||||||
window.ENTE_CONFIG = {
 | 
					window.ENTE_CONFIG = {
 | 
				
			||||||
 | 
					    // Make sure these are properly formatted URLs with protocol and domain
 | 
				
			||||||
    API_URL: 'https://${CLOUDRON_APP_FQDN}/api',
 | 
					    API_URL: 'https://${CLOUDRON_APP_FQDN}/api',
 | 
				
			||||||
    PUBLIC_ALBUMS_URL: 'https://${CLOUDRON_APP_FQDN}/public'
 | 
					    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 = window.process || {};
 | 
				
			||||||
window.process.env = window.process.env || {};
 | 
					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_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_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.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
 | 
					// Add logging to help with debugging
 | 
				
			||||||
console.log('Ente runtime config loaded from runtime-config.js');
 | 
					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('API_URL (final):', window.ENTE_CONFIG.API_URL);
 | 
				
			||||||
console.log('PUBLIC_ALBUMS_URL (final):', window.ENTE_CONFIG.PUBLIC_ALBUMS_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);
 | 
					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
 | 
					            // Next.js environment variables
 | 
				
			||||||
            window.process = window.process || {};
 | 
					            window.process = window.process || {};
 | 
				
			||||||
            window.process.env = window.process.env || {};
 | 
					            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_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_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.NEXT_PUBLIC_REACT_APP_ENTE_ENDPOINT = 'https://${CLOUDRON_APP_FQDN}/api';
 | 
				
			||||||
            window.process.env.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
 | 
					            // 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 - API_URL:', window.ENTE_CONFIG.API_URL);
 | 
				
			||||||
            console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
 | 
					            console.log('Ente config loaded - PUBLIC_ALBUMS_URL:', window.ENTE_CONFIG.PUBLIC_ALBUMS_URL);
 | 
				
			||||||
        "
 | 
					        "
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user