W
Waspβ€’2mo ago
Sahee

Different auth configurations per environment

Hello, I'm looking for a way to setup email+password login for my dev environment. For production I would like to leave only social one. Do we have any examples how to do withot multiple main.wasp files?
14 Replies
kapa.ai
kapa.aiβ€’2mo ago
Hi @Sahee. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
MEE6
MEE6β€’2mo ago
Wohooo @Sahee, you just became a Waspeteer level 1!
kapa.ai
kapa.aiβ€’2mo ago
---------------------- Wasp does not currently support dynamic configuration of authentication methods based on the environment (e.g., enabling email+password in development and only social login in production) directly within a single main.wasp file. According to a community discussion, dynamic variables in main.wasp are not supported yet, but there are plans to introduce a TypeScript-based config in the future to allow such customizations, including using environment variables to control config values. For now, you would need to manually change your main.wasp file or maintain separate versions for different environments. There is, however, a helpful environment variable for email-based auth: you can use SKIP_EMAIL_VERIFICATION_IN_DEV to skip email verification in development, but this does not affect which auth methods are enabledβ€”it only modifies the behavior of email verification during development. For your use case, you will need to manually adjust the auth methods in main.wasp when switching between environments, as there is no built-in way to automate this yet without multiple main.wasp files or manual intervention. You can follow the progress on this feature here: GitHub Issue #551 and see the related discussion in this Discord thread. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Sahee, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Carlos
Carlosβ€’2mo ago
main.wasp does not currently support this kind of conditional setup, but main.wasp.ts does! it's experimental but you can try it already if you want: https://wasp.sh/docs/general/wasp-ts-config
Wasp TypeScript config (*.wasp.ts) | Wasp
This document assumes your app works with Wasp >= 0.15.
Carlos
Carlosβ€’2mo ago
(we want to deprecate .wasp files and move entirely to .wasp.ts in the short future, so you're well set by migrating already, even if there are still some kinks to iron)
Sahee
SaheeOPβ€’2mo ago
Damn, that what I was looking for πŸ™‚ Let's migrate then
Sahee
SaheeOPβ€’2mo ago
the wasp-config is really weird, do we have any info why it's done like this:
"wasp-config": "file:../../.local/share/wasp-lang/0.16.5/data/packages/wasp-config"
"wasp-config": "file:../../.local/share/wasp-lang/0.16.5/data/packages/wasp-config"
?
Carlos
Carlosβ€’2mo ago
that is to be expected for the moment, it's in our roadmap to improve it that path is pointing inside the internal data dir of the wasp compiler, where the config spec is located
Sahee
SaheeOPβ€’2mo ago
Looks like I have a weird issue with env after migration (+wasp upgrade to latest)
[ Server ] > node --enable-source-maps -r dotenv/config bundle/server.js
[ Server ]
[ Server!]
[ Server!] ══ Env vars validation failed ══
[ Server!]
[ Server!] - Required
[ Server!]
[ Server!] ════════════════════════════════
[ Server ] > node --enable-source-maps -r dotenv/config bundle/server.js
[ Server ]
[ Server!]
[ Server!] ══ Env vars validation failed ══
[ Server!]
[ Server!] - Required
[ Server!]
[ Server!] ════════════════════════════════
I don't have any env validator Server under 3001 returns 404 for all auth methods. Something broke I've had env.ts. After some debugging it looks like
import * as z from 'zod';
const redColor = '\x1b[31m';
export function ensureEnvSchema(data, schema) {
console.log(data, schema)
try {
import * as z from 'zod';
const redColor = '\x1b[31m';
export function ensureEnvSchema(data, schema) {
console.log(data, schema)
try {
data returns undefined
[ Server ] > server@0.0.0 start
[ Server ] > node --enable-source-maps -r dotenv/config bundle/server.js
[ Server ]
[ Server!]
[ Server!] ══ Env vars validation failed ══
[ Server!]
[ Server!] - Required
[ Server!]
[ Server!] ════════════════════════════════
[ Server!] /home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/env/validation.js:16
[ Server!] throw new Error('Error parsing environment variables');
[ Server!] ^
[ Server!]
[ Server!]
[ Server!] Error: Error parsing environment variables
[ Server ] > server@0.0.0 start
[ Server ] > node --enable-source-maps -r dotenv/config bundle/server.js
[ Server ]
[ Server!]
[ Server!] ══ Env vars validation failed ══
[ Server!]
[ Server!] - Required
[ Server!]
[ Server!] ════════════════════════════════
[ Server!] /home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/env/validation.js:16
[ Server!] throw new Error('Error parsing environment variables');
[ Server!] ^
[ Server!]
[ Server!]
[ Server!] Error: Error parsing environment variables
validation js(build by wasp probbaly)
import * as z from 'zod';
const redColor = '\x1b[31m';
export function ensureEnvSchema(data, schema) {
try {
return schema.parse(data);
}
catch (e) {
if (e instanceof z.ZodError) {
const errorOutput = ['', '══ Env vars validation failed ══', ''];
for (const error of e.errors) {
errorOutput.push(` - ${error.message}`);
}
errorOutput.push('');
errorOutput.push('════════════════════════════════');
console.error(redColor, errorOutput.join('\n'));
throw new Error('Error parsing environment variables');
}
else {
throw e;
}
}
}
//# sourceMappingURL=validation.js.map
import * as z from 'zod';
const redColor = '\x1b[31m';
export function ensureEnvSchema(data, schema) {
try {
return schema.parse(data);
}
catch (e) {
if (e instanceof z.ZodError) {
const errorOutput = ['', '══ Env vars validation failed ══', ''];
for (const error of e.errors) {
errorOutput.push(` - ${error.message}`);
}
errorOutput.push('');
errorOutput.push('════════════════════════════════');
console.error(redColor, errorOutput.join('\n'));
throw new Error('Error parsing environment variables');
}
else {
throw e;
}
}
}
//# sourceMappingURL=validation.js.map
env.js (build by wasp probbaly)
import * as z from 'zod';
import { ensureEnvSchema } from '../env/validation.js';
const userClientEnvSchema = z.object({});
const waspClientEnvSchema = z.object({
REACT_APP_API_URL: z
.string({
required_error: 'REACT_APP_API_URL is required',
})
.default('http://localhost:3001')
});
const clientEnvSchema = userClientEnvSchema.merge(waspClientEnvSchema);
// PUBLIC API
export const env = ensureEnvSchema(import.meta.env, clientEnvSchema);
//# sourceMappingURL=env.js.map
import * as z from 'zod';
import { ensureEnvSchema } from '../env/validation.js';
const userClientEnvSchema = z.object({});
const waspClientEnvSchema = z.object({
REACT_APP_API_URL: z
.string({
required_error: 'REACT_APP_API_URL is required',
})
.default('http://localhost:3001')
});
const clientEnvSchema = userClientEnvSchema.merge(waspClientEnvSchema);
// PUBLIC API
export const env = ensureEnvSchema(import.meta.env, clientEnvSchema);
//# sourceMappingURL=env.js.map
Looks like the validation doesn't trigger wirht old setup, but it triggers with the new. Any ideas? import.meta.env is undefined .env.client + .env.server are in the main directory (the same path as .wasproot file). .wasp/out/server contains .env file
Carlos
Carlosβ€’2mo ago
this env.js you've shared is from the client and it seems you might be importing it from the server?
Sahee
SaheeOPβ€’2mo ago
Yes, for sure it's executing it in server, don't really know why
[ Server!] /home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/env/validation.js:17
[ Server!] throw new Error('Error parsing environment variables');
[ Server!] ^
[ Server!]
[ Server!]
[ Server!] Error: Error parsing environment variables
[ Server!] at ensureEnvSchema (/home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/env/validation.js:17:19)
[ Server!] at <anonymous> (/home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/client/env.js:13:20)
[ Server!] /home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/env/validation.js:17
[ Server!] throw new Error('Error parsing environment variables');
[ Server!] ^
[ Server!]
[ Server!]
[ Server!] Error: Error parsing environment variables
[ Server!] at ensureEnvSchema (/home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/env/validation.js:17:19)
[ Server!] at <anonymous> (/home/rafal/projects/zenivy/.wasp/out/sdk/wasp/dist/client/env.js:13:20)
app.server({
middlewareConfigFn: { import: 'middlewareConfig', from: '@src/middleware.ts' },
setupFn: { importDefault: 'setup', from: '@src/setup_server.ts' },
})

app.client({
rootComponent: { import: 'Root', from: '@src/Root' },
setupFn: { importDefault: 'setup', from: '@src/setup_client.ts' },
});

/*
app.server({
middlewareConfigFn: { import: 'middlewareConfig', from: '@src/middleware.ts' },
setupFn: { importDefault: 'setup', from: '@src/setup_server.ts' },
})

app.client({
rootComponent: { import: 'Root', from: '@src/Root' },
setupFn: { importDefault: 'setup', from: '@src/setup_client.ts' },
});

/*
Carlos
Carlosβ€’2mo ago
maybe check in the middleware or server files if you have any wasp/client import
Sahee
SaheeOPβ€’2mo ago
You are 100% correct Used import { useAuth } from 'wasp/client/auth'; in client & server side code 10/10 support Thank you!
Carlos
Carlosβ€’2mo ago
happy to have helped! rock on!

Did you find this page helpful?