From 48e37251dfa99ad314a61d31902183633f150f28 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 7 Feb 2026 16:41:59 -0800 Subject: [PATCH] Return JSON errors for signup and handle in GUI --- src/backend/src/routers/signup.js | 10 +++++----- src/gui/src/initgui.js | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/backend/src/routers/signup.js b/src/backend/src/routers/signup.js index 8a84d94d6..5f67edce9 100644 --- a/src/backend/src/routers/signup.js +++ b/src/backend/src/routers/signup.js @@ -120,7 +120,7 @@ module.exports = eggspress(['/signup'], { await svc_event.emit('puter.signup', event); if ( ! event.allow ) { - return res.status(400).send(event.error ?? 'You are not allowed to sign up.'); + return res.status(400).send({ message: event.error ?? 'You are not allowed to sign up.', code: 'not_allowed_to_signup' }); } // check if user is already logged in @@ -153,19 +153,19 @@ module.exports = eggspress(['/signup'], { const is_user_signup_disabled = await lazy_user_signup(); if ( is_temp_users_disabled && is_user_signup_disabled ) { - return res.status(403).send('User signup and Temporary users are disabled.'); + return res.status(403).send({ message: 'User signup and Temporary users are disabled.', code: 'user_signup_and_temp_users_disabled' }); } if ( !req.body.is_temp && is_user_signup_disabled ) { - return res.status(403).send('User signup is disabled.'); + return res.status(403).send({ message: 'User signup is disabled.', code: 'user_signup_disabled' }); } if ( req.body.is_temp && is_temp_users_disabled ) { - return res.status(403).send('Temporary users are disabled.'); + return res.status(403).send({ message: 'Temporary users are disabled.', code: 'temp_users_disabled' }); } if ( req.body.is_temp && event.no_temp_user ) { - return res.status(403).send('You must login or signup.'); + return res.status(403).send({ message: 'You must login or signup.', code: 'must_login_or_signup' }); } // Create temp user data diff --git a/src/gui/src/initgui.js b/src/gui/src/initgui.js index 73539d478..27075a3b7 100644 --- a/src/gui/src/initgui.js +++ b/src/gui/src/initgui.js @@ -1111,9 +1111,26 @@ window.initgui = async function (options) { document.dispatchEvent(new Event('login', { bubbles: true })); }, error: async (err) => { - UIAlert({ - message: html_encode(err.responseText), - }); + let err_obj = null; + try { + err_obj = JSON.parse(err.responseText); + } catch (e) { + err_obj = e; + } + if ( err_obj.code === 'must_login_or_signup' ) { + await UIWindowSignup({ + reload_on_success: false, + send_confirmation_code: false, + window_options: { + has_head: false, + cover_page: window.is_embedded || window.is_fullpage_mode, + }, + }); + } else { + UIAlert({ + message: err_obj.message ?? 'There was an error creating your account. Please try again.', + }); + } }, complete: function () {