title: Firebase Authentication link not working - missing trailing slash?
body: <p>I want to use Firebase email link authentication in my iOS (Flutter) app with a <strong>custom domain</strong>:</p>
  
  <ol>
  <li><p>The app requests Firebase Auth backend to send an email to the user. -- works</p></li>
  <li><p>The user clicks a link in the email and is taken back to the app. -- works</p></li>
  <li><p>The app processes the payload of that link to perform the sign in. -- does not work</p></li>
  </ol>
  
  <p>Firebase Dynamic Links do work in general but the link from that particular Firebase auto-generated email is not. Technically the app is brought to foreground but the Firebase Dynamic Link <code>onLink</code> callback is not fired. I tracked it down to one tiny trailing slash that is missing in the email's link URL:</p>
  
  <pre><code>https://link.mydomain.com?link=https://app.mydomain.com/__/auth/action?apiKey=... (not working)
  
  https://link.mydomain.com/?link=https://app.mydomain.com/__/auth/action?apiKey=... (works)
  -------------------------^
  </code></pre>
  
  <p>To work around this I tried to add a path suffix to my domain but this gave the same results:</p>
  
  <pre><code>https://link.mydomain.com/app?link=https://app.mydomain.com/__/auth/action?apiKey=... (not working)
  
  https://link.mydomain.com/app/?link=https://app.mydomain.com/__/auth/action?apiKey=... (works)
  -----------------------------^
  </code></pre>
  
  <p>The worst part of this difference that made it so hard to find is that if you copy the link on iOS or long press it to see a preview, the slash is just silently added in the right place! You can paste the link to the notes app, click it, and it works!</p>
  
  <p>Only when viewing the email's source code you can see that it is actually not there:</p>
  
  <p><a href="https://i.stack.imgur.com/T2YRR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T2YRR.png" alt="Screenshot from email source code"></a></p>
  
  <p>When requesting the link, I call <code>FirebaseAuth.instance.sendSignInWithEmailLink</code> with these params set:</p>
  
  <pre><code>url: 'https://app.mydomain.com',
  dynamicLinkDomain: 'link.mydomain.com',
  </code></pre>
  
  <p>The <code>dynamicLinkDomain</code> param does not accept a protocol or path.</p>
  
  <p><strong>Does anybody know how to...</strong></p>
  
  <ul>
  <li>make Firebase add this slash to the link when sending the mail?</li>
  </ul>
  
  <p>or</p>
  
  <ul>
  <li>make Firebase Dynamic Link's <code>onLink</code> callback react to clicked links that do not have a trailing slash?</li>
  </ul>
  
  <hr>
  
  <p><strong>For reference</strong></p>
  
  <p>My Info.plist contains this key:</p>
  
  <pre><code>&lt;key&gt;FirebaseDynamicLinksCustomDomains&lt;/key&gt;
  &lt;array&gt;
      &lt;string&gt;https://link.mydomain.com&lt;/string&gt;
  &lt;/array&gt;
  </code></pre>
  
  <p>My entitlements file contains this key:</p>
  
  <pre><code>&lt;key&gt;com.apple.developer.associated-domains&lt;/key&gt;
  &lt;array&gt;
      &lt;string&gt;applinks:link.mydomain.com&lt;/string&gt;
  &lt;/array&gt;
  </code></pre>
  
  <p>apple-app-site-association (<a href="https://link.mydomain.com/apple-app-site-association" rel="nofollow noreferrer">https://link.mydomain.com/apple-app-site-association</a>):</p>
  
  <pre><code>{
    "applinks": {
      "apps": [],
      "details": [{
        "appID": "XYZ.com.mydomain.app",
        "paths": [
          "NOT /_/*",
          "/*"
        ]
      }]
    }
  }
  </code></pre>