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
Hi @Sahee. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Wohooo @Sahee, you just became a Waspeteer level 1!
----------------------
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?
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-configWasp TypeScript config (*.wasp.ts) | Wasp
This document assumes your app works with Wasp >= 0.15.
(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)
Damn, that what I was looking for π Let's migrate then
the wasp-config is really weird, do we have any info why it's done like this:
?
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
Looks like I have a weird issue with env after migration (+wasp upgrade to latest)
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
data returns undefined
validation js(build by wasp probbaly)
env.js (build by wasp probbaly)
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
this
env.js
you've shared is from the client
and it seems you might be importing it from the server?Yes, for sure it's executing it in server, don't really know why
maybe check in the middleware or server files if you have any
wasp/client
importYou are 100% correct
Used import { useAuth } from 'wasp/client/auth'; in client & server side code
10/10 support
Thank you!
happy to have helped! rock on!