Starting from an email link, I'm trying to log in the user and then redirect the user to a protected route. I was trying to do this by setting the state value in the configFusionAuth object and then using the state value in the onRedirect callback to set the route.
I'm using React SDK with an express backend. When using the link generated by generateProtectedUrl (see code below), I'm able to open the login form and log in, but state value is always undefined.
What is the general approach to setting up this workflow?
This is my logic to generate the email link.
async generateProtectedUrl(path) {
try {
const clientId = config.clientID;
const baseUrl = config.fusionAuthBaseUrl;
const redirectUri = 'http://localhost:5173';
const state = 'test';
const authUrl = new URL(`${baseUrl}/oauth2/authorize`);
const params = {
client_id: clientId,
scope: 'openid offline_access',
response_type: 'code',
redirect_uri: redirectUri,
state: state,
};
Object.entries(params).forEach(([key, value]) => {
authUrl.searchParams.append(key, value);
});
return authUrl.toString();
} catch (error) {
console.error('Error generating protected URL:', error);
throw error;
}
}