redirectURI without the domain?
Right now I have to do this:
return new GitHubStrategy(
{
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
redirectURI: 'https://www.epicstack.dev/auth/github/callback',
},
async () => {
// ...
}
)
But I want to be able to do this:
return new GitHubStrategy(
{
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
redirectURI: '/auth/github/callback',
},
async () => {
// ...
}
)
And then the strategy would get the domain from the request.
This would make it so we can run this locally and on staging. Additionally with this improvement people wouldn't have to change this hard-coded URL when creating an epic app.
For now I've updated it to an environment variable, but I still think it would be nice to not have to configure that.
The solution I recommend is that instead of making the strategy be smart about how to format the endpoint based on the hostname of the app, let the app itself do it.
You can create a function that receives the Request, and creates and return the Authenticator with the strategy.
export function createAuthenticator(request: Request) {
let authenticator = new Authenticator<T>()
authenticator.use(
new GitHubStrategy({ redirectURI: new URL("/auth/github/callback", request.url) }, verify)
)
return authenticator
}
This way you're in control of how to generate the redirectURI based on the request.url.
So you recommend dynamically creating a new authenticator per request?
Yes, the class itself is really simple and can be discarded after the response is sent. If it ever becomes an issue you could use cachified to ensure it's created once after the first request.
You could also create the Authenticator once at the module level, and only create the strategy in a function as that's the only part that depends on the Request.
That's a little different from the way everyone seems to use remix-auth (including how the docs recommend using it). Any reason you can't make the redirectURI support a function that accepts the request?
Mostly because every strategy needs to do it, and that way to use Remix Auth is also the way to use it on Cloudflare Workers app as you need to pass any env variable from the AppLoadContext so you need to create the strategies from inside a function.