Skip to content

Commit 0b40ada

Browse files
authored
feat(auth): use new firebase login methods- prescottprue#467 - @kadikraman
2 parents aa05bbe + abf8bac commit 0b40ada

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/actions/auth.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,23 @@ export const login = (dispatch, firebase, credentials) => {
448448
if (!userData) return Promise.resolve(null)
449449

450450
// For email auth return uid (createUser is used for creating a profile)
451-
if (method === 'signInWithEmailAndPassword') {
451+
if (
452+
[
453+
'signInWithEmailAndPassword',
454+
'signInAndRetrieveDataWithEmailAndPassword'
455+
].includes(method)
456+
) {
452457
return { user: userData }
453458
}
454459
// TODO: Only call createUserProfile once, and just pass different settings
455460

456461
// For token auth, the user key doesn't exist. Instead, return the JWT.
457-
if (method === 'signInWithCustomToken') {
462+
if (
463+
[
464+
'signInWithCustomToken',
465+
'signInAndRetrieveDataWithCustomToken'
466+
].includes(method)
467+
) {
458468
if (!firebase._.config.updateProfileOnLogin) {
459469
return { user: userData }
460470
}

src/utils/auth.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export const getLoginMethodAndParams = (firebase, creds) => {
9797
return { method: 'signInWithRedirect', params: [authProvider] }
9898
}
9999
if (token) {
100+
const tokenAuth = firebase.auth().signInAndRetrieveDataWithCustomToken
101+
102+
if (tokenAuth) {
103+
return { method: 'signInAndRetrieveDataWithCustomToken', params: [token] }
104+
}
105+
100106
return { method: 'signInWithCustomToken', params: [token] }
101107
}
102108
if (phoneNumber) {
@@ -110,6 +116,17 @@ export const getLoginMethodAndParams = (firebase, creds) => {
110116
params: [phoneNumber, applicationVerifier]
111117
}
112118
}
119+
120+
const emailPasswordAuth = firebase.auth()
121+
.signInAndRetrieveDataWithEmailAndPassword
122+
123+
if (emailPasswordAuth) {
124+
return {
125+
method: 'signInAndRetrieveDataWithEmailAndPassword',
126+
params: [email, password]
127+
}
128+
}
129+
113130
return { method: 'signInWithEmailAndPassword', params: [email, password] }
114131
}
115132

test/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const fakeFirebase = {
129129
130130
providerData: [{}]
131131
}),
132-
signInWithCustomToken: () => {
132+
signInAndRetrieveDataWithCustomToken: () => {
133133
return Promise.resolve({
134134
toJSON: () => ({
135135
stsTokenManager: {

0 commit comments

Comments
 (0)