Closed argus-ralph closed 9 months ago
Because you are throwing the redirect, you catch it also in the try catch black so after checking the error you should throw if what you caught is actually a redirect
export async function action({ request, params }: DataFunctionArgs) {
const dataSourceName = DataSourceNameSchema.parse(params['data_source'])
try {
return await dataSourceAuthenticator.authenticate(dataSourceName, request)
} catch (error: unknown) {
console.log(error)
if (error instanceof Response) {
console.log(await error.json())
const formData = await request.formData()
const rawRedirectTo = formData.get('redirectTo')
const redirectTo =
typeof rawRedirectTo === 'string'
? rawRedirectTo
: getReferrerRoute(request)
const redirectToCookie = getRedirectCookieHeader(redirectTo)
if (redirectToCookie) {
error.headers.append('set-cookie', redirectToCookie)
}
}
throw error
}
}
Currently I call the authenticator.authenticate function with the remix-auth-facebook strategy whenever someone posts to the following route with this action, where dataSource corresponds to Facebook:
And the authenticate function stops working whenever remix-auth-oauth2 tries to redirect the user to the provided callback URL
The logged error is equal to:
I have no idea why it is giving me this error. I found a solution where I return the redirect as follows:
But this is ofcourse not ideal. Do you have any suggestions on what I can do here or is anyone else experiencing this?