Why firebase signInWithEmailAndPassword doesn't trigger onAuthChange?What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?Why does ++[[]][+[]]+[+[]] return the string “10”?Add Extra Details on Firebase User TableFirebase authentication (is not a function, is not a constructor)How to disable Signup in Firebase 3.xFirebase WEB - Email Verification not being sent. What's wrong with the codeFirebase Google Auth users not showing in Firebase Consolefirebase users login through mobileFirebase auth doesn't retain the login details in firebase web
How to write a convincing religious myth?
How far would a landing Airbus A380 go until it stops with no brakes?
Multicolumn Output
Is it okay to have a sequel start immediately after the end of the first book?
How precise must a satellite's orbit be?
How do you play "tenth" chords on the guitar?
Equilibrium constant for a solid-solid equilibrium
Extracting data from Plot
Do empty drive bays need to be filled?
Could a person damage a jet airliner - from the outside - with their bare hands?
Comparing arithmetic complexity of FFT radix-2 and convolution
Grep Match and extract
Confused with atmospheric pressure equals plastic balloon’s inner pressure
I've been given a project I can't complete, what should I do?
Latex - unable to get proper boxes
Who is "He that flies" in Lord of the Rings?
Increase speed altering column on large table to NON NULL
Make Gimbap cutter
What differences exist between adamantine and adamantite in all editions of D&D?
Housemarks (superimposed & combined letters, heraldry)
How do we say "within a kilometer radius spherically"?
Does the new finding on "reversing a quantum jump mid-flight" rule out any interpretations of QM?
How to avoid typing 'git' at the begining of every Git command
Are polynomials with the same roots identical?
Why firebase signInWithEmailAndPassword doesn't trigger onAuthChange?
What is JSONP, and why was it created?Why does Google prepend while(1); to their JSON responses?Why does ++[[]][+[]]+[+[]] return the string “10”?Add Extra Details on Firebase User TableFirebase authentication (is not a function, is not a constructor)How to disable Signup in Firebase 3.xFirebase WEB - Email Verification not being sent. What's wrong with the codeFirebase Google Auth users not showing in Firebase Consolefirebase users login through mobileFirebase auth doesn't retain the login details in firebase web
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have the following function triggered when an user logs in:
const auth = firebase.auth();
export const signIn = ( email, password ) => (
auth.signInWithEmailAndPassword( email, password )
.catch(e => e ? console.log(e) : console.log(auth.currentUser))
);
If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.
When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).
And as it's not too suprising,
export const getUser = () => (
async dispatch => (
auth.onAuthStateChanged(user =>
const uid = user = ;
console.log(user)
if (uid)
console.log(uid)
dispatch(
setUserId(
uid
)
)
else
console.log("nologin")
)
)
);
just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.
javascript firebase firebase-authentication
add a comment |
I have the following function triggered when an user logs in:
const auth = firebase.auth();
export const signIn = ( email, password ) => (
auth.signInWithEmailAndPassword( email, password )
.catch(e => e ? console.log(e) : console.log(auth.currentUser))
);
If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.
When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).
And as it's not too suprising,
export const getUser = () => (
async dispatch => (
auth.onAuthStateChanged(user =>
const uid = user = ;
console.log(user)
if (uid)
console.log(uid)
dispatch(
setUserId(
uid
)
)
else
console.log("nologin")
)
)
);
just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.
javascript firebase firebase-authentication
add a comment |
I have the following function triggered when an user logs in:
const auth = firebase.auth();
export const signIn = ( email, password ) => (
auth.signInWithEmailAndPassword( email, password )
.catch(e => e ? console.log(e) : console.log(auth.currentUser))
);
If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.
When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).
And as it's not too suprising,
export const getUser = () => (
async dispatch => (
auth.onAuthStateChanged(user =>
const uid = user = ;
console.log(user)
if (uid)
console.log(uid)
dispatch(
setUserId(
uid
)
)
else
console.log("nologin")
)
)
);
just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.
javascript firebase firebase-authentication
I have the following function triggered when an user logs in:
const auth = firebase.auth();
export const signIn = ( email, password ) => (
auth.signInWithEmailAndPassword( email, password )
.catch(e => e ? console.log(e) : console.log(auth.currentUser))
);
If I type in incorrect details, the error is logged into the console, but if the details are correct, nothing happens.
When I check the network data in devtools, the request returns all the data it should, but inside the app, auth.currentUser is undefined (checked after log-in as well).
And as it's not too suprising,
export const getUser = () => (
async dispatch => (
auth.onAuthStateChanged(user =>
const uid = user = ;
console.log(user)
if (uid)
console.log(uid)
dispatch(
setUserId(
uid
)
)
else
console.log("nologin")
)
)
);
just gets triggered initially, when the app loads, with undefined and nologin. Inside the firebase console, authentication with email and password enabled, and the users are valid. I know it should work, as I made many authentication process through firebase, in the same way, so I can't provide more information, if you had the same problem, and you solved it, please let me know.
javascript firebase firebase-authentication
javascript firebase firebase-authentication
edited Mar 24 at 21:32
Doug Stevenson
93.2k10106126
93.2k10106126
asked Mar 24 at 21:09
Gergő HorváthGergő Horváth
628216
628216
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:
Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.
Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.
Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.
I do it like that and so far has worked all the time. Good luck!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328608%2fwhy-firebase-signinwithemailandpassword-doesnt-trigger-onauthchange%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:
Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.
Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.
Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.
I do it like that and so far has worked all the time. Good luck!
add a comment |
yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:
Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.
Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.
Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.
I do it like that and so far has worked all the time. Good luck!
add a comment |
yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:
Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.
Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.
Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.
I do it like that and so far has worked all the time. Good luck!
yes, I think this is related to the async nature of the Firebase design. So signInWithEmail... works, but it doesn't immediately reflect the change on the currentUser object. Instead, use the event onAuthStateChanged to do any code related to the currentUser. The process would be:
Register the onAuthStateChanged event, and inside it detect for currentUser == null, this event will always get called on first definition with a null user, so by putting an if inside you can detect when you're dealing with an actual signIn.
Add the signIn function, but don't do anything on the callback with the currentuser here, instead move the relevant code to onAuthStageChanged.
Also, not 100% sure that you have to wrap the event inside a module and export it, or that you should. When doing web apps, each page is supposed to be state-less and independent, so each page should have its own script code to check for auth events and do whatever is appropriate.
I do it like that and so far has worked all the time. Good luck!
answered Mar 24 at 21:33
Sergio FloresSergio Flores
31017
31017
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328608%2fwhy-firebase-signinwithemailandpassword-doesnt-trigger-onauthchange%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown