516a3fa72c
- Modified setup/2.post.ts to check for WG_HOST and WG_CLIENT_PORT overrides - If both overrides are set, auto-populate host/port and mark setup as complete - Updated setup/2.vue to check setup status after user creation and redirect appropriately - Modified setup middleware to allow access to success page during setup - Setup now completes after step 2 when host/port are provided via environment variables Co-authored-by: kaaax0815 <32197462+kaaax0815@users.noreply.github.com>
35 lines
917 B
TypeScript
35 lines
917 B
TypeScript
/* First setup of wg-easy */
|
|
export default defineEventHandler(async (event) => {
|
|
const url = getRequestURL(event);
|
|
|
|
// User can't be logged in, and public routes can be accessed whenever
|
|
if (url.pathname.startsWith('/api/')) {
|
|
return;
|
|
}
|
|
|
|
const { step, done } = await Database.general.getSetupStep();
|
|
if (!done) {
|
|
const parsedSetup = url.pathname.match(/\/setup\/(\d|migrate|success)/);
|
|
if (!parsedSetup) {
|
|
return sendRedirect(event, `/setup/1`, 302);
|
|
}
|
|
const [_, currentSetup] = parsedSetup;
|
|
|
|
// Allow access to success page during setup
|
|
if (currentSetup === 'success') {
|
|
return;
|
|
}
|
|
|
|
if (step.toString() === currentSetup) {
|
|
return;
|
|
}
|
|
return sendRedirect(event, `/setup/${step}`, 302);
|
|
} else {
|
|
// If already set up
|
|
if (!url.pathname.startsWith('/setup/')) {
|
|
return;
|
|
}
|
|
return sendRedirect(event, '/login', 302);
|
|
}
|
|
});
|