Giter Site home page Giter Site logo

oijusti / react-native-firebaseui-auth Goto Github PK

View Code? Open in Web Editor NEW
42.0 3.0 10.0 2.03 MB

Easily add sign-in to your React Native app with FirebaseUI

License: MIT License

Java 28.05% JavaScript 1.67% Ruby 7.04% Objective-C 53.95% TypeScript 8.06% Objective-C++ 1.24%
firebase android ios react-native react-native-app react auth javascript firebaseui

react-native-firebaseui-auth's Introduction

oijusti

Build Status

npm version PR's welcome

install size

react-native-firebaseui-auth

Easily add sign-in to your React Native app with FirebaseUI

Getting started

Add Firebase to your project

Android:

  1. Follow the Android setup guide
  2. Follow the sign-in methods guide

iOS:

  1. Follow the iOS setup guide

  2. Add FirebaseUI to your Podfile:

    pod 'FirebaseUI'
    

    Run $ pod update

  3. Follow the sign-in methods guide

Installation

$ npm install react-native-firebaseui-auth --save

or

$ yarn add react-native-firebaseui-auth

Linking (RN >= 0.60 skip this step)

RN <= 0.59 only

Automatic

$ react-native link react-native-firebaseui-auth

Manual

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-firebaseui-auth and add RNFirebaseuiAuth.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNFirebaseuiAuth.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.oijusti.firebaseuiauth.RNFirebaseuiAuthPackage; to the imports at the top of the file
  • Add new RNFirebaseuiAuthPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-firebaseui-auth'
    project(':react-native-firebaseui-auth').projectDir = new File(rootProject.projectDir,  '../node_modules/react-native-firebaseui-auth/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      implementation project(':react-native-firebaseui-auth')
    

Usage

import Auth, {AuthEventEmitter, AuthEvents} from 'react-native-firebaseui-auth';

...

  componentDidMount() {
    this.eventListener = AuthEventEmitter.addListener(
      AuthEvents.AUTH_STATE_CHANGED,
      event => {
        console.log('user:', event.user);
      }
    );
  }

  componentWillUnmount() {
    this.eventListener.remove(); //Removes the listener
  }

...

  const config = {
    providers: [
      'anonymous',
      'facebook', 
      'google', 
      'email', 
      'phone', 
      'apple', 
      'yahoo', 
      'github', 
      'twitter', 
      'microsoft'
    ],
    tosUrl: 'https://example.com/tos.htm',
    privacyPolicyUrl: 'https://example.com/privacypolicy.htm',
  };

  Auth.signIn(config)
    .then(user => console.log(user))
    .catch(err => console.log(err));

...

  Auth.getCurrentUser().then(user => console.log(user));

...

  Auth.signOut().then(res => console.log(res));

...

  Auth.deleteUser().then(res => console.log(res));

...

Returns: user

Field Type Description
uid string The provider's user ID for the user.
displayName string The name of the user.
photoURL string The URL of the user's profile photo.
email string Indicates the email address associated with this user has been verified.
phoneNumber string A phone number associated with the user.
providerId string The provider identifier.
isNewUser boolean Indicates whether or not the current user was signed in for the first time.
creationTimestamp number Stores the timestamp at which this account was created as dictated by the server clock in milliseconds since epoch.
lastSignInTimestamp number Stores the last signin timestamp as dictated by the server clock in milliseconds since epoch.

UI Customization

Optionally, you can use the option customizations to change the look of the authentication screens. This does not apply to the actual sign-in buttons and their position. What you can change depends on the platform.

Android

The values available for android customization are as follows,

  const config = {
    ...
    customizations: [
      'theme',
      'logo'
    ],
  };

First add FirebaseUI in your build.gradle (:app),

dependencies {
    implementation 'com.firebaseui:firebase-ui-auth:6.4.0'
    ...

For theme, add the next style in your styles.xml, then copy into the drawable folder an image to use for background and name it auth_background.png.

    <style name="AuthTheme" parent="FirebaseUI">
        <!-- <item name="colorPrimary">@color/colorPrimary</item> -->
        <!-- <item name="colorPrimaryDark">@color/colorPrimaryDark</item> -->
        <!-- <item name="colorAccent">@color/colorAccent</item> -->

        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorControlActivated">@android:color/white</item>
        <item name="colorControlHighlight">@android:color/white</item>
        <item name="android:windowBackground">@drawable/auth_background</item>
    </style>

For logo, copy an image in the drawable folder and name it auth_logo.png.

iOS

The values available for iOS customization correspond to specific screens and are as follows,

  const config = {
    ...
    customizations: [
      'auth_picker',
      'email_entry',
      'password_sign_in',
      'password_sign_up',
      'password_recovery',
      'password_verification'
    ],
  };

Open your project in XCode and add the .xib file of the screen you want to customize. The .xib files are located in ./ios/custom-screens/ of this library. Let's say, you want to customize the auth-picker screen, add the file FUICustomAuthPickerViewController.xib and use the XCode tools to add it labels, images, change colors, and so on.

Email Password Settings

You can control whether new users can sign in or not by using the option allowNewEmailAccounts. Also, if you do not want to require the user name during sign up you can set the option requireDisplayName to false.

  const config = {
    ...
    allowNewEmailAccounts: false,
    requireDisplayName: false,
  };

Anonymous User upgrade Settings

When an anonymous user signs in or signs up with a permanent account, the autoUpgradeAnonymousUsers option allows you to link the existing account (anonymous) with permanent account. This way the user can continue with what they were doing before signing up. By default this option is disabled.

  const config = {
    ...
    autoUpgradeAnonymousUsers: true,
  };

Example Project

Create a project in the Firebase Console and add apps for Android and iOS. Then enable Email/Password provider in Authentication.

Android

Make sure you type com.example in the Android package name field.

Download the file google-services.json in the android/app folder.

iOS

Make sure you type com.example in the iOS bundle ID field.

Download the file GoogleService-Info.plist in the ios/example folder and add it into the project using xcode.

Update pods $ pod install

Contributing

Feel free to report bugs, ask questions and submit a PR.

If this is your first open source contribution, please take a look at this guide .

Find this library useful?

Please give me a star ✭ if you like it!

License

(MIT)

react-native-firebaseui-auth's People

Contributors

achuinard avatar dependabot[bot] avatar mjsirisha88 avatar oijusti avatar oleksandra-holovina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-firebaseui-auth's Issues

Installation fails to run the app

Hi I just installed this package and when i run the app on my device I get the following error:

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find any matches for com.twitter.sdk.android:twitter-core:3.+ as no versions of com.twitter.sdk.android:twitter-core are available.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/com/twitter/sdk/android/twitter-core/maven-metadata.xml
       - file:/Users/user/.m2/repository/com/twitter/sdk/android/twitter-core/
       - file:/Users/user/repos/app/android/App/node_modules/react-native/android/com/twitter/sdk/android/twitter-core/maven-metadata.xml
       - file:/Users/user/repos/app/android/App/node_modules/jsc-android/dist/com/twitter/sdk/android/twitter-core/maven-metadata.xml
       - https://dl.google.com/dl/android/maven2/com/twitter/sdk/android/twitter-core/maven-metadata.xml
       - https://www.jitpack.io/com/twitter/sdk/android/twitter-core/maven-metadata.xml
     Required by:
         project :app > project :react-native-firebaseui-auth

any ideas? I don't even need the twitter implementaton
Thanks

get custom token information

I'm developing a react-native application. I've added a custom token to a user's firebase authentication. Is it possible to retrieve that custom token information using react-native-firebaseui-auth? Or is it possible to access the user accessToken?

M1 issues?

I'm getting a strange error trying to use this on my new M1 Mac.

node_modules/react-native-firebaseui-auth/ios/RNFirebaseuiAuth.m normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'react-native-firebaseui-auth' from project 'Pods')

Did I do something wrong?

No Apple auth

Great project. I see it doesn't support Apple sign-in though. I may open a PR for this with the fixes but wanted to first file an issue.

Run iOS example error

Hi, i want to use this lib, but when i try to run example in iOS i can't
I follow steps in README.md but i catch this error: "Module 'FBSDKCoreKit' not found".

Do exists any additional step not listeted on the README.md?

'FirebaseUI/FirebaseUI.h' file not found

after npm install, and pod install i getting this error also the library not found for -lFBSDKLoginKit
Screenshot 2021-11-22 at 10 12 43

i have added to my podFile

  pod 'FirebaseUI'
  pod 'FBSDKCoreKit', :modular_headers => true

and after pod install the frameworks are installed

Installing FirebaseUI (4.1.1)
Installing FBSDKCoreKit 12.1.0

but there are not visible in my project.

i have removed all modules and package-lock, pods and reinstall it again, but no success.
What should i do next to make it work?

Should facebook Android SDK version be bumped up?

After integrating Facebook auth for Android, Facebook developer console gives a warning that SDK needs to be upgraded. Following change gets rid of the warning:

--- node_modules/react-native-firebaseui-auth/android/build.gradle-orig	2020-08-13 16:31:42.000000000 -0400
+++ node_modules/react-native-firebaseui-auth/android/build.gradle	2020-08-13 16:31:52.000000000 -0400
@@ -49,7 +49,7 @@
 
     // Required only if Facebook login support is required
     // Find the latest Facebook SDK releases here: https://goo.gl/Ce5L94
-    implementation 'com.facebook.android:facebook-android-sdk:4.+'
+    implementation 'com.facebook.android:facebook-android-sdk:[5,6]'
 
     // Required only if Twitter login support is required
     // Find the latest Twitter SDK releases here: https://goo.gl/E5wZvQ

Are there reasons not to make this change?

Working with latest FirebaseUI pod?

I'm using FirebaseUI 12 and get this error when trying to run my React Native app:

FirebaseUI/FirebaseEmailAuthUI.h' file not found

#import <FirebaseUI/FirebaseEmailAuthUI.h>

Does this work with the latest FirebaseUI pod?

Promise.reject instead of resolve on failure

When signin has an error we call Promise resolve. This makes the application logic a little bit more complex, as it needs to check for failure inside Promise.then(). It seems Promise.reject would make more sense:

--- RNFirebaseuiAuthModule.java	2020-08-12 21:10:31.000000000 -0400
+++ RNFirebaseuiAuthModule.java	2020-08-16 00:47:56.000000000 -0400
@@ -137,7 +137,8 @@
           try {
             WritableMap resultData = new WritableNativeMap();
             resultData.putString("success", "false");
-            signInPromise.resolve(resultData);
+            resultData.putInt("code", resultCode);
+            signInPromise.reject("101", "code " + resultCode /*resultData*/);
           } catch (Exception e) {
             e.printStackTrace();
             signInPromise.reject("101", e.getMessage());

To trigger failure one could just try to cancel signIn. I tested it on android but I assume ios has the same logic. Look for to your comment. Thanks

Can't build app

I'm not sure what else would help debug this, but here is a screenshot of the error log

image

Pass isNewUser?

I know on the Android side on the FirebaseUI Auth activity result you can check if the user was a new signup or not. Are you able to do that somehow with iOS? I don't know if the same API is supported but if so it would be nice to pass that data through to the callback so I can do something special in my app if the sign-in created a new user.

Change background

Hi, thanks for module! It will be nice if there in config will be some UI configs such as background Image , color, something like that

Can't sign in with Google

Email sign in works, but when I try to sign in with Google, I'm getting a toast "Code: 10, Message: 10:" and nothing happens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.