<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hcmlopes</title>
    <description>The latest articles on DEV Community by hcmlopes (@hcmlopes).</description>
    <link>https://dev.to/hcmlopes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F74908%2Fe88a9ba0-bf34-406c-b9bb-67de470e20a0.jpg</url>
      <title>DEV Community: hcmlopes</title>
      <link>https://dev.to/hcmlopes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hcmlopes"/>
    <language>en</language>
    <item>
      <title>Local Nuxt 3 - Firebase signInWithRedirect</title>
      <dc:creator>hcmlopes</dc:creator>
      <pubDate>Thu, 03 Oct 2024 18:00:09 +0000</pubDate>
      <link>https://dev.to/hcmlopes/local-nuxt-3-firebase-signinwithredirect-599n</link>
      <guid>https://dev.to/hcmlopes/local-nuxt-3-firebase-signinwithredirect-599n</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I decided to write this article as it took a few days to wrap my head around and fix the issue.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The requirement
&lt;/h2&gt;

&lt;p&gt;You want to create your app with firebase auth using the &lt;code&gt;signInWithRedirect&lt;/code&gt; method so that you have a good experience in mobile and desktop.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;With new strict rules placed by the browsers, when you try to develop using &lt;code&gt;localhost&lt;/code&gt; Google OAuth doesn't want to play nice.&lt;/p&gt;

&lt;p&gt;After nearly exhausting my google skills I found some small threads of information that led me to a working solution that I will describe here.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Disclaimer: If you are reading this, I assume you have a working firebase config and setup and just want to make sure auth works.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Nuxt Config - Route Rules

&lt;ul&gt;
&lt;li&gt;Go to your Firebase config and add a new route rule for proxying the requests from your localhost to the firebase app domain.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nx"&gt;routeRules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/__/auth/**&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;proxy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://&amp;lt;your-app-domain&amp;gt;.firebaseapp.com/__/auth/**&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Firebase Config

&lt;ul&gt;
&lt;li&gt;Change the &lt;code&gt;authDomain&lt;/code&gt; in your firebaseConfig to your localhost address where the development server will run eg.: &lt;code&gt;authDomain: 'localhost:3000'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Package.json

&lt;ul&gt;
&lt;li&gt;Update the &lt;code&gt;dev&lt;/code&gt; script to include the https flag for nuxt development with a self signed certificate.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;nuxt dev --https&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Google Cloud Console config

&lt;ul&gt;
&lt;li&gt;Do not be afraid of going into Cloud Console. I now the benefit of using firebase is so you don't have to get into the guts of google cloud, however as far as I know this configuration is not made available in firebase console.&lt;/li&gt;
&lt;li&gt;Go to Google API Console &lt;a href="https://console.developers.google.com/apis/credentials" rel="noopener noreferrer"&gt;Credentials page&lt;/a&gt;. make sure to have the correct Project selected.&lt;/li&gt;
&lt;li&gt;Look for the section titled &lt;strong&gt;OAuth 2.0 Client IDs&lt;/strong&gt; and click the Web client entry as shown in the screenshot
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fom6rpbnhfctbtgsllqhk.png" alt="Image description"&gt;
&lt;/li&gt;
&lt;li&gt;Scroll down to Authorized Redirect URIs and add your localhost url with the HTTPS protocol as shown in the screenshot and save. * Make sure the adjust the port as necessary based on your setup
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fojgvwtxpeq51e6t2hvwg.png" alt="Image description"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Restart project
&lt;/h2&gt;

&lt;p&gt;Once you have completed all of the necessary changes you should be able to restart your nuxt app by typing &lt;code&gt;yarn dev&lt;/code&gt; (or use the pkg mngr of your choice), accept the browser warning due to using the self signed cert&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8j0zrhen9ks6djuridu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8j0zrhen9ks6djuridu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything should now work as expected.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is my first post so if you find any mistakes or have any feedback please let me know&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nuxt</category>
      <category>firebase</category>
      <category>signinwithredirect</category>
    </item>
  </channel>
</rss>
