Link anonymous user with logged in user, possible bug. componentDidMount not called anymore.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- firebase, javascript, react
- Domain
- authentication, frontend
Research direction
Reproduce the clean-account flow with autoUpgradeAnonymousUsers enabled, using the Login component, LoginProvider, StyledFirebaseAuth, and the shown uiConfig callbacks. Trace loginProvider.register callbacks and the isSignedIn state transition to determine why componentDidUpdate no longer triggers; done means the cause and expected redirect behavior are documented or verified.
Written by the indexing model from the issue text.
Description
Hello,
first of all Happy Easter.
I think there is a bug when using autoUpgradeAnonymousUsers: true in uiConfig.
I will paste my code and I'll explain how to reproduce.
initialization code:
const uiConfig = {
signInFlow: 'popup',
c
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
],
callbacks: {
signInSuccessWithAuthResult: () => {
console.log('signInSuccessWithAuthResult')
return false
},
signInFailure: (error: any) => {
console.log('sign')
if (error.code != 'firebaseui/anonymous-upgrade-merge-conflict') {
return Promise.resolve();
}
var cred = error.credential;
return firebase.auth().signInWithCredential(cred);
}
},
};
const loginProvider = new FirebaseLoginProvider(
firebaseApp, uiConfig
);
loginProvider.register((user) => {
if (user == null) {
console.log('null')
firebaseApp.auth().signInAnonymously().catch((error) => {
console.log(error);
})
} else {
console.log("Anony " + user.isAnonymous)
}
})
And this is my react component:
import 'firebase/auth';
import './firebase-global.css';
import * as React from 'react';
import { RouteComponentProps, withRouter } from "react-router-dom";
import LoginProvider from './LoginProvider';
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth';
interface Props {
};
interface State {
isSignedIn: boolean
}
interface HomeProps extends RouteComponentProps<Props> {
loginProvider: LoginProvider
}
class Login extends React.Component<HomeProps, State> {
state = {
isSignedIn: false
}
constructor(props: HomeProps) {
super(props);
}
componentDidMount() {
console.log('componentDidMount')
this.props.loginProvider.register((user) => {
if (user != null && !user.isAnonymous) {
this.setState({ isSignedIn: true } as State);
} else {
this.setState({ isSignedIn: false } as State);
}
})
}
componentDidUpdate() {
console.log('componentDidUpdate')
this.goBackWhenLoggedIn();
}
componentWillUnmount() {
console.log('componentWillUnmount')
this.props.loginProvider.unregister();
}
render() {
const signedIn = this.state.isSignedIn
return (
<div className='container'>
{!signedIn &&
<div>
<StyledFirebaseAuth
className='firebaseUi'
uiConfig={this.props.loginProvider.actualConfig()}
firebaseAuth={this.props.loginProvider.actualProvider()} />
</div>
}
</div>
);
}
private goBackWhenLoggedIn() {
if (this.state.isSignedIn) {
// this.props.loginProvider.promoteAccount()
this.props.history.goBack()
}
}
}
export default withRouter(Login);
After login, before adding the option autoUpgradeAnonymousUsers: true for which I also had to add
signInFailure: (error: any) => {
console.log('sign')
if (error.code != 'firebaseui/anonymous-upgrade-merge-conflict') {
return Promise.resolve();
}
var cred = error.credential;
return firebase.auth().signInWithCredential(cred);
}
based on documentation from Handling anonymous user upgrade merge conflicts paragraph on https://firebase.google.com/docs/auth/web/firebaseui
I don't get redirected successfully WHEN I have a clean situation for my user meaning I delete my anonymous user and my logged in user from firebase console (Manage users).
Before, after logging in on Google, componentDidUpdate was called and I could succesfully be redirected to the last page using react router. Now I can't anymore.
What I did to solve the issue is to use window.history.back(); inside signInSuccessWithAuthResult function.
Am I doing something wrong with the configuration? I can't understand why componentDidUpdate is not fired anymore.
- Dominant language
- JavaScript
- Stars
- 1.3k
- Forks
- 246
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from firebase/firebaseui-web-react
-
This Project Is Dead Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
firebase/firebaseui-web-react#292 · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 1/100
firebase/firebaseui-web-react#280 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
firebase/firebaseui-web-react#220 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
firebase/firebaseui-web-react#210 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 20/100
firebase/firebaseui-web-react#201 · 1 comment · 1 reaction ·
All issues in firebase/firebaseui-web-react
Similar issues
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
open-webui/open-webui#30750 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Mend: dependency security vulnerability untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 70/100