From 52713426d1a443ec3007ab626459c38a2695e7b1 Mon Sep 17 00:00:00 2001 From: Salakar Date: Fri, 17 Mar 2017 23:51:26 +0000 Subject: [PATCH] [js] implemented remaining auth providers on auth() : auth(). EmailAuthProvider, GithubAuthProvider, FacebookAuthProvider, TwitterAuthProvider and GoogleAuthProvider --- .../invertase/firebase/auth/RNFirebaseAuth.java | 2 +- lib/modules/auth/index.js | 17 ++++++++++++----- lib/modules/auth/providers/Facebook.js | 9 +++++++++ lib/modules/auth/providers/Github.js | 9 +++++++++ lib/modules/auth/providers/Google.js | 9 +++++++++ lib/modules/auth/providers/Twitter.js | 9 +++++++++ 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 lib/modules/auth/providers/Facebook.js create mode 100644 lib/modules/auth/providers/Github.js create mode 100644 lib/modules/auth/providers/Google.js create mode 100644 lib/modules/auth/providers/Twitter.js diff --git a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java index 75058b89..deb4ee52 100644 --- a/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java +++ b/android/src/main/java/io/invertase/firebase/auth/RNFirebaseAuth.java @@ -415,7 +415,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule { case "facebook": return FacebookAuthProvider.getCredential(authToken); case "google": - return GoogleAuthProvider.getCredential(authToken, null); + return GoogleAuthProvider.getCredential(authToken, authSecret); case "twitter": return TwitterAuthProvider.getCredential(authToken, authSecret); case "github": diff --git a/lib/modules/auth/index.js b/lib/modules/auth/index.js index 962ba072..3264f3d3 100644 --- a/lib/modules/auth/index.js +++ b/lib/modules/auth/index.js @@ -3,12 +3,17 @@ import { NativeModules, NativeEventEmitter } from 'react-native'; import User from './user'; import { Base } from './../base'; + +// providers import EmailAuthProvider from './providers/Email'; +import GoogleAuthProvider from './providers/Google'; +import FacebookAuthProvider from './providers/Facebook'; +import TwitterAuthProvider from './providers/Twitter'; +import GithubAuthProvider from './providers/Github'; const FirebaseAuth = NativeModules.RNFirebaseAuth; const FirebaseAuthEvt = new NativeEventEmitter(FirebaseAuth); -// TODO move user methods to user class export default class Auth extends Base { _user: User|null; _authResult: AuthResultType | null; @@ -21,11 +26,13 @@ export default class Auth extends Base { this.authenticated = false; // attach auth providers - // TODO add missing providers this.EmailAuthProvider = EmailAuthProvider; - // start listening straight away - // generally though the initial event fired will get ignored - // but this is ok as we fake it with the getCurrentUser below + this.GoogleAuthProvider = GoogleAuthProvider; + this.FacebookAuthProvider = FacebookAuthProvider; + this.TwitterAuthProvider = TwitterAuthProvider; + this.GithubAuthProvider = GithubAuthProvider; + + // start listening immediately for auth changes FirebaseAuthEvt.addListener('onAuthStateChanged', this._onAuthStateChanged.bind(this)); FirebaseAuth.addAuthStateListener(); } diff --git a/lib/modules/auth/providers/Facebook.js b/lib/modules/auth/providers/Facebook.js new file mode 100644 index 00000000..ffe032bb --- /dev/null +++ b/lib/modules/auth/providers/Facebook.js @@ -0,0 +1,9 @@ +export default { + credential(token) { + return { + token, + secret: '', + provider: 'facebook', + }; + }, +}; diff --git a/lib/modules/auth/providers/Github.js b/lib/modules/auth/providers/Github.js new file mode 100644 index 00000000..96a72c28 --- /dev/null +++ b/lib/modules/auth/providers/Github.js @@ -0,0 +1,9 @@ +export default { + credential(token) { + return { + token, + secret: '', + provider: 'github', + }; + }, +}; diff --git a/lib/modules/auth/providers/Google.js b/lib/modules/auth/providers/Google.js new file mode 100644 index 00000000..2e7177ed --- /dev/null +++ b/lib/modules/auth/providers/Google.js @@ -0,0 +1,9 @@ +export default { + credential(token, secret) { + return { + token, + secret, + provider: 'google', + }; + }, +}; diff --git a/lib/modules/auth/providers/Twitter.js b/lib/modules/auth/providers/Twitter.js new file mode 100644 index 00000000..1a769089 --- /dev/null +++ b/lib/modules/auth/providers/Twitter.js @@ -0,0 +1,9 @@ +export default { + credential(token, secret) { + return { + token, + secret, + provider: 'twitter', + }; + }, +};