[
  {
    "path": ".gitignore",
    "content": ".DS_Store\n.idea\n*.iml\nnode_modules/\n*.log*\nnpm-debug.log\n*.pyc\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing\nWe're always looking to improve this project, open source contribution is encouraged so long as they adhere to our guidelines.\n\n# Pull Requests\n\nThe Solid State team will be monitoring for pull requests. When we get one, a member of team will test the work against our internal uses and sign off on the changes. From here, we'll either merge the pull request or provide feedback suggesting the next steps.\n\n**A couple things to keep in mind:**\n\n - If you've changed APIs, update the documentation.\n - Keep the code style (indents, wrapping) consistent.\n - If your PR involves a lot of commits, squash them using ```git rebase -i``` as this makes it easier for us to review.\n - Keep lines under 80 characters.\n"
  },
  {
    "path": "README.md",
    "content": "**This is the react-native implementation of https://github.com/SolidStateGroup/simple-firebase-auth**\n\n# React Native Firebase Auth\n\n[![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/SolidStateGroup/react-native-firebase-auth?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nSimplified Firebase authentication for React Native projects with support for Facebook & Google login.\n\nUsing this module alongside Firebase means there is no need to write and host any backend code to handle users logging in to your app.\n\nUse our project starter repository (https://github.com/SolidStateGroup/firebase-project-starter) to help you get started setting up your own Firebase project.\n\n\n## Installation\n\n```\n$ npm install --save react-native-firebase-auth\n```\n\n**Note:** If you use React Native < `v0.39` or you are already using `react-native-google-signin` then stick with `v0.0.11` (`npm install react-native-firebase-auth@0.0.11 --save`)\n\n## Project Setup\n\n```\n$ npm install --save firebase react-native-facebook-login react-native-google-sign-in\n```\n\nYou will need fully setup both of the below social platform dependencies (react-native-google-sign-in and react-native-facebook-login).\n\nhttps://github.com/joonhocho/react-native-google-sign-in#getting-started\nhttps://github.com/magus/react-native-facebook-login#setup\n\nYou will need to initialise Firebase within your app in the usual way. See https://firebase.google.com/docs/web/setup\n\n## Usage\n\n```\nimport FireAuth from 'react-native-firebase-auth';\n\nconstructor(props) {\n  super(props);\n  FireAuth.init({iosClientId: <IOS_CLIENT_ID>}); // This is the CLIENT_ID found in your Google services plist.\n}\n\ncomponentDidMount() {\n  FireAuth.setup(this.onLogin, this.onUserChange, this.onLogout, this.emailVerified, this.onError);\n}\n\nregister = () => {\n  const { email, password, firstName, lastName } = this.state;\n  FireAuth.register(email, password, { firstName, lastName });\n}\n\nlogin = () => {\n  FireAuth.login(this.state.email, this.state.password);\n}\n\nloginAnonymously = () => {\n  FireAuth.loginAnonymously();\n}\n\nfacebookLogin() {\n  FireAuth.facebookLogin();\n}\n\ngoogleLogin() {\n  FireAuth.googleLogin();\n}\n\nlogout() {\n  FireAuth.logout();\n}\n\nupdate () => {\n  FireAuth.update({\n    firstName: this.state.firstName,\n    lastName: this.state.lastName\n  }).then(() => {\n    ...\n  }).catch(err => {\n    ...\n  });\n}\n\nresetPassword () => {\n  FireAuth.resetPassword(this.state.email)\n    .then(() => {\n      ...\n    })\n    .catch(err => {\n      ...\n    });\n}\n\nupdatePassword () => {\n  FireAuth.updatePassword(this.state.password)\n    .then(() => {\n      ...\n    })\n    .catch(err => {\n      ...\n    });\n}\n\n```\n\n## Credits\n\nhttps://github.com/magus/react-native-facebook-login\n\nhttps://github.com/joonhocho/react-native-google-sign-in\n\n# Getting Help\nIf you encounter a bug or feature request we would like to hear about it. Before you submit an issue please search existing issues in order to prevent duplicates.\n\n# Contributing\nFor more information about contributing PRs, please see our <a href=\"CONTRIBUTING.md\">Contribution Guidelines</a>.\n\n\n# Get in touch\nIf you have any questions about our projects you can email <a href=\"mailto:projects@solidstategroup.com\">projects@solidstategroup.com</a>.\n"
  },
  {
    "path": "auth.js",
    "content": "import { FBLoginManager } from 'react-native-facebook-login';\nimport GoogleSignIn from 'react-native-google-sign-in';\n\nconst Facebook = {\n  login: (permissions) => {\n    return new Promise((resolve, reject) => {\n      FBLoginManager.loginWithPermissions(permissions || ['email'], (error, data) => {\n        if (!error) {\n          resolve(data.credentials.token);\n        } else {\n          reject(error);\n        }\n      });\n    });\n  },\n  logout: () => {\n    return new Promise((resolve, reject) => {\n      FBLoginManager.logout((error, data) => {\n        if (!error) {\n          resolve(true);\n        } else {\n          reject(error);\n        }\n      });\n    });\n  }\n}\n\nconst Google = {\n  configure: (options) => {\n    GoogleSignIn.configure(options);\n  },\n  login: () => {\n    return new Promise((resolve, reject) => {\n      GoogleSignIn.signInPromise()\n        .then((user) => {\n          resolve(user.accessToken);\n        })\n        .catch((err) => {\n          reject(err);\n        })\n        .done();\n    });\n  },\n  logout: () => {\n    return new Promise((resolve, reject) => {\n      GoogleSignIn.signOutPromise()\n        .then(() => {\n          resolve(true);\n        })\n        .catch((err) => {\n          reject(err);\n        });\n    });\n  }\n}\n\nconst Auth = {Facebook, Google};\n\nexport default Auth;\n"
  },
  {
    "path": "index.js",
    "content": "import * as firebase from 'firebase';\nimport Auth from './auth';\n\nconst FireAuth = class {\n  user = null;\n  profile = null;\n  onUserChange = null;\n  onLogout = null;\n  onEmailVerified = null;\n  onLogin = null;\n  onError = null;\n\n  init(googleConfig) {\n    Auth.Google.configure(googleConfig);\n  }\n\n  setup = (onLogin, onUserChange, onLogout, onEmailVerified, onError) => {\n    this.onUserChange = onUserChange;\n    this.onLogout = onLogout;\n    this.onEmailVerified = onEmailVerified;\n    this.onLogin = onLogin;\n    this.onError = onError;\n\n    firebase.auth().onAuthStateChanged((user)=> {\n\n      if (user) {\n        // Determine if user needs to verify email\n        var emailVerified = !user.providerData || !user.providerData.length || user.providerData[0].providerId != 'password' || user.emailVerified;\n\n        // Upsert profile information\n        var profileRef = firebase.database().ref(`profiles/${user.uid}`);\n        profileRef.update({ emailVerified: emailVerified, email: user.email });\n\n        profileRef.on('value', (profile)=> {\n          const val = profile.val();\n\n          // Email become verified in session\n          if (val.emailVerified && (this.profile && !this.profile.val().emailVerified)) {\n            this.onEmailVerified && this.onEmailVerified();\n          }\n\n          if (!this.user) {\n            this.onLogin && this.onLogin(user, val); // On login\n          } else if (val) {\n            this.onUserChange && this.onUserChange(user, val); // On updated\n          }\n\n          this.profile = profile; // Store profile\n          this.user = user; // Store user\n        });\n\n      } else {\n        this.profile = null;\n        this.user = null; // Clear user and logout\n        this.onLogout && this.onLogout();\n      }\n\n    });\n  }\n\n  login = (email, password) => {\n    try {\n      firebase.auth().signInWithEmailAndPassword(email, password)\n        .catch((err) => this.onError && this.onError(err));\n    } catch (e) {\n      this.onError && this.onError(e);\n    }\n  }\n\n  loginAnonymously = () => {\n    try {\n      firebase.auth().signInAnonymously()\n        .catch((err) => this.onError && this.onError(err));\n    } catch (e) {\n      this.onError && this.onError(e);\n    }\n  }\n\n  register = (username, password) => {\n    try {\n      firebase.auth().createUserWithEmailAndPassword(username, password)\n        .then((user)=> {\n          user.sendEmailVerification();\n        })\n        .catch((err) => this.onError && this.onError(err));\n    } catch (e) {\n      this.onError && this.onError(e);\n    }\n  }\n\n  resendVerification = () => {\n    this.user.sendEmailVerification();\n  }\n\n  facebookLogin = (permissions) => {\n    Auth.Facebook.login(permissions)\n      .then((token) => (\n        firebase.auth()\n          .signInWithCredential(firebase.auth.FacebookAuthProvider.credential(token))\n      ))\n      .catch((err) => this.onError && this.onError(err));\n  }\n\n  googleLogin = () => {\n    Auth.Google.login()\n      .then((token) => (\n        firebase.auth()\n          .signInWithCredential(firebase.auth.GoogleAuthProvider.credential(null, token))\n      ))\n      .catch((err) => this.onError && this.onError(err));\n  }\n\n  logout = () => {\n    firebase.auth().signOut();\n  }\n\n  update = (data) => {\n    var profileRef = firebase.database().ref(`profiles/${this.user.uid}`);\n    return profileRef.update(data);\n  }\n\n  resetPassword = (email) => {\n    firebase.auth().sendPasswordResetEmail(email);\n  }\n\n  updatePassword = (password) => {\n    this.user.updatePassword(password);\n  }\n\n  linkWithGoogle = () => {\n    // @TODO\n  }\n\n  linkWithFacebook = () => {\n    // @TODO\n  }\n\n  linkWithEmail = () => {\n    // @TODO\n  }\n};\n\nexport default new FireAuth();\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"react-native-firebase-auth\",\n  \"version\": \"1.0.1\",\n  \"description\": \"Simplified Firebase authentication with social platform support\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"keywords\": [\n    \"react-native\",\n    \"auth\",\n    \"social\",\n    \"facebook\",\n    \"login\",\n    \"google\",\n    \"firebase\"\n  ],\n  \"author\": \"SSG\",\n  \"license\": \"ISC\",\n  \"peerDependencies\": {\n    \"firebase\": \">=3.0.0\",\n    \"react-native\": \">=0.30.0\",\n    \"react-native-facebook-login\": \">=1.4.0\",\n    \"react-native-google-sign-in\": \">=0.0.8\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/SolidStateGroup/react-native-firebase-auth.git\"\n  },\n  \"bugs\": {\n    \"url\": \"https://github.com/SolidStateGroup/react-native-firebase-auth/issues\"\n  },\n  \"homepage\": \"https://github.com/SolidStateGroup/react-native-firebase-auth#readme\"\n}\n"
  }
]