Comments (7)
Hi ,
thank you for your request.
I need more information, such as what configuration you are using this plugin in, to help you out.
Please provide a Minimal, Reproducible Example (see How to create a Minimal, Reproducible Example).
from capacitor-firebase-authentication.
Hello I created a PR on your demo app, in browser this is just working fine, but this should not work on capacitor app on android. Can you test it, I can not build your demo on mobile right now but it should reproduce
When you have a loo to the code compare, I really did only few lines of code
robingenz/capacitor-firebase-authentication-demo#73
from capacitor-firebase-authentication.
My demo app uses native authentication. If you want to use Angularfire Guards, you need to use the Firebase JS SDK. This requires some modifications: see https://github.com/robingenz/capacitor-firebase-authentication/blob/main/docs/firebase-js-sdk.md.
The other possibility would be that you create your own guards which call https://github.com/robingenz/capacitor-firebase-authentication#getcurrentuser.
Is there a way you can handle this anyway? If not we have to make our own guards, but it should be nice if we can use the standards.
So to answer your question: Unfortunately there is nothing I can do about it. You have to use one of the two options and implement the adjustments in your app.
For this reason, I am closing this issue. Please let me know if you have any further questions.
from capacitor-firebase-authentication.
@robingenz Yeah I know but the problem of the custom guards with FirebaseAuthentication.getCurrentUser() is that when I do a page reload for example on developing he current user is not available when guard is called, just a 1-2 seconds later
I'll have a look on doing it with skipNativeAuth, may I ask, which is the diff using firebase js sdk instead of using native auth, I mean from your part. Less performant or what else?
from capacitor-firebase-authentication.
Yeah I know but the problem of the custom guards with FirebaseAuthentication.getCurrentUser() is that when I do a page reload for example on developing he current user is not available when guard is called, just a 1-2 seconds later
Maybe this service will help you:
import { Injectable } from '@angular/core';
import {
FirebaseAuthentication,
User,
} from '@robingenz/capacitor-firebase-authentication';
import { Observable, ReplaySubject } from 'rxjs';
import { map, take } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class FirebaseAuthenticationService {
private currentUserSubject = new ReplaySubject<User | undefined>(1);
constructor() {
FirebaseAuthentication.addListener('authStateChange', result => {
this.currentUserSubject.next(result.user || undefined);
});
}
public get currentUser$(): Observable<User | undefined> {
return this.currentUserSubject.asObservable();
}
public get currentUserId$(): Observable<string | undefined> {
return this.currentUserSubject.asObservable().pipe(map(user => user?.uid));
}
public getCurrentUser(): Promise<User | undefined> {
return this.currentUser$.pipe(take(1)).toPromise();
}
public getCurrentUserId(): Promise<string | undefined> {
return this.currentUserId$.pipe(take(1)).toPromise();
}
public async signInWithApple(): Promise<void> {
await FirebaseAuthentication.signInWithApple();
}
public async signInWithGoogle(): Promise<void> {
await FirebaseAuthentication.signInWithGoogle();
}
public async signOut(): Promise<void> {
await FirebaseAuthentication.signOut();
}
public async getIdToken(): Promise<string> {
const result = await FirebaseAuthentication.getIdToken();
return result.token;
}
}
I use this in my apps to deal with this behavior.
I'll have a look on doing it with skipNativeAuth, may I ask, which is the diff using firebase js sdk instead of using native auth, I mean from your part. Less performant or what else?
Please have a look at the FAQ. I just extended it to include this question.
from capacitor-firebase-authentication.
Okay but in this scenario I have to wait a lot to get resolved the guards, something which ends in my opinion in a laggy behaviour.
Now I'm using the skipNativeAuth with your example, which works fine. Perhaps you should also describe in this scenario you have also to signout from both layers doing something like this
public async logout(): Promise<void> {s
await FirebaseAuthentication.signOut();
return signOut(this.auth);
}
At least I have todo it
from capacitor-firebase-authentication.
Okay but in this scenario I have to wait a lot to get resolved the guards, something which ends in my opinion in a laggy behaviour.
Yes that's right, you have to wait for the Promise. I have implemented a custom SplashScreen for it, which supports web.
Perhaps you should also describe in this scenario you have also to signout from both layers doing something like this
Thanks for the tip. I will add that.
from capacitor-firebase-authentication.
Related Issues (20)
- bug: Error: invalid credential when signInWithCredential using idToken after closing & re-opening app HOT 2
- Info about how to add firebase app HOT 3
- bug: Facebook returns no email adress HOT 6
- bug: getCurrentUser returns undefined user HOT 2
- feat: Convert an anonymous account to a permanent account HOT 2
- Login persistent , I have to sigin everytime with the phone number and otp , but firebase uses cookies to persist tokens , make that auto sigin . HOT 1
- I would like to get the usage of firebase storage, how can i implement , there is no auth provided , i am talking about with the security rules ( allow read, write: if request.auth != null ) HOT 1
- bug: Resend otp in phone auth ? HOT 1
- bug: SignInOptions not working HOT 2
- bug:
- bug: iOS Sign in Not Persisting HOT 1
- bug: `addListener('authStateChange', ...)` callback is never get called HOT 9
- bug: Firebase Instance ID Depreciation warning HOT 6
- bug: hard crash after calling signInWithPhoneNumber HOT 1
- bug: Sign back in with Apple - Duplicate User HOT 11
- bug: reCAPTCHA shows an error after release. This request is missing a valid app identifier HOT 2
- bug: not compatible with other firebase community plugins HOT 5
- bug: iOS directions fail to install required Firebase pods for M1 Mac HOT 1
- bug: Issue with Facebook SignIn accessToken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capacitor-firebase-authentication.