firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

ionic/capacitor ios apps failing to login using firebase js sdk or angularfire

Open vaishnavm217 opened this issue 3 years ago • 2 comments

[REQUIRED] Describe your environment

  • Operating System version: iOS 15.6
  • Browser version: - (iOS webview)
  • Firebase SDK version: 9.9.1
  • Firebase Product: auth

[REQUIRED] Describe the problem

All the auth requests are being denied from firebase saying FirebaseError:( auth/requests-from-capacitor://localhost-are-blocked). Tried this https://github.com/angular/angularfire/issues/3087#issuecomment-1063822400, still fails.

This started appearing out of nowhere , 2-3 weeks back it was working perfectly, and whole development process has come to standstill. First Assumed this was angularfire error, but same is reproduced using firebase js sdk.

I have checked both domains in firebase (localhost is added) and API HTTP restrictions in GCP are removed. Still the same.

I suspect urlscheme (capacitor:// orionic://) to be the culprit, but not sure if this the case, as changelog here says it has been included, but still it shows up

Steps to reproduce:

  • Install firebase js sdk, capacitor and initialize ios app
  • Use email/password provider
  • Get custom token from server
  • Add custom token login code in frontend
  • build the ios app, and publish to testflight (or use iOS emulator - didnt test there)

Relevant Code:

# Firebase service
import { Injectable } from '@angular/core';
import { initializeApp } from '@firebase/app';
import { getAuth, signInWithCustomToken, Auth, indexedDBLocalPersistence,User } from '@firebase/auth';
import { from, Observable } from 'rxjs';
import { environment } from 'src/environments/environment';

@Injectable({
  providedIn: 'root'
})
export class FirebaseauthService {
  private auth:Auth
  private app:any
  constructor() {
    this.app = initializeApp(environment.firebase)
    this.auth = getAuth(this.app)
    this.auth.tenantId = environment.tenantId
    this.auth.setPersistence(indexedDBLocalPersistence).then(()=>{
      console.log("Changed persistance")
    })
    // setPersistence(this.auth,indexedDBLocalPersistence).then(()=>{
    //   console.log("Change persistence")
    // })
  }
  signInCustomToken(token:any){
    return signInWithCustomToken(this.auth, token)
  }
  getUser(){
    return new Observable<User>(res=>{res.next(this.auth.currentUser)})
  }
  getIdToken(){
    return from(this.auth.currentUser.getIdToken())
  }
  signOut(){
    return this.auth.signOut()
  }
}
# Login component
constructor(private auth: FirebaseauthService,) {}
login(){
    this.auth.signInCustomToken(CUSTOM_TOKEN_FROM_SERVER).then((res:any) => {
      this.router.navigate(['/customerLanding']);
      this.spinner.hide();
    })
  }

vaishnavm217 avatar Aug 04 '22 14:08 vaishnavm217

I have the same issue as @vaishnavm217 and am awaiting fix.

SheldonHage avatar Sep 09 '22 13:09 SheldonHage

This was mistake from my side. I was using wrong key during my production build which was deleted.

Weird thing is google error said it's not allowed access rather than saying it's expired key

vaishnavm217 avatar Sep 09 '22 13:09 vaishnavm217

Hi @vaishnavm217,

Could you confirm that this is not an issue for you? Thanks!

DellaBitta avatar May 28 '23 17:05 DellaBitta

Hey @vaishnavm217. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Jun 02 '23 01:06 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@vaishnavm217 if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Jun 08 '23 01:06 google-oss-bot