• Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login
FusionAuth
  • Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login

Email with link to protected route

Scheduled Pinned Locked Moved Solved
Comments & Feedback
2
3
1.2k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    randall
    last edited by mark.robustelli 21 Feb 2025, 17:55

    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;
        }
      }
    
    M 1 Reply Last reply 21 Feb 2025, 18:34 Reply Quote 0
    • M
      mark.robustelli @randall
      last edited by 21 Feb 2025, 18:34

      @randall have you checked out the documentation using Magic Links? Does this get you what you need or am I missing something?

      R 1 Reply Last reply 24 Feb 2025, 04:17 Reply Quote 0
      • R
        randall @mark.robustelli
        last edited by 24 Feb 2025, 04:17

        @mark-robustelli Thanks for pointing this out! Yes, magic links will work nicely.

        1 Reply Last reply Reply Quote 0
        • M mark.robustelli marked this topic as a question on 25 Feb 2025, 14:32
        • M mark.robustelli has marked this topic as solved on 25 Feb 2025, 14:32
        3 out of 3
        • First post
          3/3
          Last post