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.1k
    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

      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;
          }
        }
      
      mark.robustelliM 1 Reply Last reply Reply Quote 0
      • mark.robustelliM
        mark.robustelli @randall
        last edited by

        @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 Reply Quote 0
        • R
          randall @mark.robustelli
          last edited by

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

          1 Reply Last reply Reply Quote 0
          • mark.robustelliM mark.robustelli marked this topic as a question on
          • mark.robustelliM mark.robustelli has marked this topic as solved on
          • First post
            Last post