Closed jimmycallin closed 3 months ago
Create the authenticator and strategy on the request, that way you can extract the hostname from the request.url.
export async function getAuthenticator(url: URL) {
let authenticator = new Authenticator(sessionStorage, options)
let options = { redirectURI: new URL("/auth/github/callback", url), ...moreOptions }
authenticator.use(new OAuth2Strategy(options, verify)
return authenticator;
}
And then in your loader:
export async function loader({ request }: LoaderFunctionArgs) {
let url = new URL(request.url)
let auth = getAuthenticator(url)
await auth.authenticate(request, "oauth2", options)
// rest of your code
}
Aah, of course! I for some reason assumed authenticators needed to be defined on module level.
Thank you!
Hi!
Would it be possible to enable allowing to set the redirectURI based on the request object? In particular, I would like to be able to set the host of the redirectURI. In my current app environment, the hostname is not available as an environment variable and we automatically generate PR servers, making dynamically setting the redirectURI quite useful.
Thanks!