Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67f3384
Return file snapshot on upload (#88)
urbantumbleweed Mar 24, 2017
5edc780
feat(react-native): react-native and boilerplate support (#90)
prescottprue Mar 24, 2017
2d1bbb7
Added XMLHttpRequest to tests (to fix firebase auth issue)
Mar 24, 2017
0ffacb0
react-native complete example started.
Mar 24, 2017
224de4e
Firebase showing up in react-native example.
Mar 24, 2017
78f3ed4
Home now displays auth in a string.
Mar 25, 2017
2b2f429
react-native now working with firebase js library
prescottprue Mar 25, 2017
cc0ad58
Switched to ReactNative instead of rn
prescottprue Mar 25, 2017
d65aa2f
Version v1.4.0-beta (#97)
prescottprue Mar 26, 2017
04039a2
Version v1.4.0 Beta 2 (#100)
prescottprue Mar 28, 2017
5042759
Version v1.4.0 Beta 3 (#101)
prescottprue Mar 28, 2017
27d64e7
Merge branch 'master' into v1.4.0
prescottprue Mar 30, 2017
acd14f9
Merge branch 'master' into v1.4.0
Apr 1, 2017
c960361
Version 1.4.0 Beta 4 (#105)
prescottprue Apr 3, 2017
459c222
Version v1.4.0 Release Candidate 1 (#110)
prescottprue Apr 5, 2017
23bb32a
Form utils added to example.
prescottprue Apr 10, 2017
bc64cf5
Roadmap updated with info on nested populates and updateProfile method.
Apr 15, 2017
b3c87bd
Merge branch 'master' into v1.4.0
Apr 15, 2017
d4b86d1
Server side rendering notes added.
Apr 26, 2017
d7943f5
Merge branch 'master' into v1.4.0
May 5, 2017
36de200
Support for custom auth parameters added.
May 5, 2017
6b2826c
Merge branch 'master' into v1.4.0
May 5, 2017
e478d03
notParsed query parameter. isLoaded returns true issue (#121)
May 5, 2017
85e968e
Use prop-types package instead of the bundled prop-types (#122)
petetnt May 5, 2017
7dbe7b2
key: true lists support for profileParamsToPopulate (#123)
fej-snikduj May 5, 2017
ff11deb
Fixed typos in material-example
May 6, 2017
e89e381
Fixed the last of the "react" typos within material example.
May 6, 2017
3655517
Firebase updated to v3.9.0. More material example updates.
prescottprue May 6, 2017
4e629a9
Lint removed.
prescottprue May 6, 2017
e53dc19
More lint removal from material-ui example.
prescottprue May 6, 2017
caa9bd4
Added message to clarify home container.
prescottprue May 6, 2017
c964724
Not populated delete working in material-ui example
prescottprue May 6, 2017
c92a563
Pull request template updated. Roadmap updated with react-native-fire…
prescottprue May 16, 2017
90489f6
SSR and Auth sections added to recipes. Roadmap updated for coming v1…
prescottprue May 16, 2017
4404433
Merge branch 'master' into v1.4.0
prescottprue May 16, 2017
12df1e8
Auth Recipes cleaned up.
prescottprue May 16, 2017
b49e98f
Version v1.4.0-rc.3 (#128) (#134)
prescottprue May 16, 2017
d86b06d
Exposing Firebase messaging added to roadmap for v1.5.0.
May 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switched to ReactNative instead of rn
* Switched to using ReactNative instead of rn
* Roadmap updated with `react-native` stuff
* react-native complete example README added
  • Loading branch information
prescottprue committed Mar 25, 2017
commit cc0ad58f8512a325a694a233ec90864c9bb17d47
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [Epics](/docs/recipes/epics.md)
* [Routing](/docs/recipes/routing.md)
* [Redux Form](/docs/recipes/redux-form.md)
* [React Native](/docs/recipes/react-native.md)
* [Populate](/docs/recipes/populate.md)
* [API Reference](/docs/api/README.md)
* [constants](/docs/api/constants.md)
Expand Down
140 changes: 77 additions & 63 deletions docs/recipes/react-native.md
Original file line number Diff line number Diff line change
@@ -1,131 +1,145 @@
# React Native

**NOTE**: Only works for versions `v1.4.0-alpha` and higher. It is still in the early stages of support.
[react-native complete example app](/examples/complete/react-native)

**NOTE**: Only works for versions `v1.4.0-beta` and higher. It is still in the early stages of support.

## Setup

1. Click "Add Firebase To iOS"
<!-- TODO: Confirm this and get a picture -->
1. Download `GoogleService-info.plist`
1. Place `GoogleService-info.plist` in the folder of whichever platform you are using (i.e. `/ios`)
1. Make sure you correctly setup [`react-native-google-signin`](https://github.com/devfd/react-native-google-signin) (means you should end up with a `GoogleSDK` folder in the folder matching your platform)
1. Copy your client id out of the `GoogleService-info.plist` file (should end in `.apps.googleusercontent.com`)
1. Place the client id into `iosClientId` variable within the example


## Example App Snippet

This snippet is a condensed version of [react-native complete example](/examples/complete/react-native).

```js
import React, { Component } from 'react';
import React, { Component } from 'react'
import { GoogleSignin, GoogleSigninButton } from 'react-native-google-signin'
import { firebaseConnect, pathToJS, isLoaded } from 'react-redux-firebase'
import { connect } from 'react-redux'
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
} from 'react-native';
} from 'react-native'
import configureStore from './store'
const initialState = { firebase: { authError: null, auth: undefined }}
const store = configureStore(initialState)

import { GoogleSignin, GoogleSigninButton } from 'react-native-google-signin';
const iosClientId = '499842460400-teaflfd8695oilltk5qkvl5688ebgq6b.apps.googleusercontent.com' // get this from plist file

class SigninSampleApp extends Component {
state = {
user: null
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
})

@firebaseConnect()
@connect(({ firebase }) => ({
auth: pathToJS(firebase, 'auth', undefined)
}))
export default class GoogleSigninSampleApp extends Component {
componentDidMount() {
this._setupGoogleSignin();
this._setupGoogleSignin()
}

render() {
if (!this.state.user) {
const { auth } = this.props
if (!isLoaded(auth)) {
return (
<View style={styles.container}>
<Text>Loading...</Text>
</View>
)
}
if (!this.props.auth) {
return (
<View style={styles.container}>
<GoogleSigninButton
style={{width: 212, height: 48}}
size={GoogleSigninButton.Size.Standard}
color={GoogleSigninButton.Color.Auto}
onPress={this._signIn.bind(this)}
onPress={() => this._signIn()}
/>
</View>
);
}

if (this.state.user) {
return (
<View style={styles.container}>
<Text style={{fontSize: 18, fontWeight: 'bold', marginBottom: 20}}>
Welcome {this.state.user.name}
</Text>
<Text>Your email is: {this.state.user.email}</Text>

<TouchableOpacity onPress={() => {this._signOut(); }}>
<View style={{marginTop: 50}}>
<Text>Log out</Text>
</View>
</TouchableOpacity>
</View>
);
)
}
return (
<View style={styles.container}>
<Text style={{fontSize: 18, fontWeight: 'bold', marginBottom: 20}}>
Welcome {this.props.auth.displayName}
</Text>
<Text>
Your email is: {this.props.auth.email}</Text>

<TouchableOpacity onPress={() => {this._signOut() }}>
<View style={{marginTop: 50}}>
<Text>Log out</Text>
</View>
</TouchableOpacity>
</View>
)
}

// based on react-native-google-signin example
async _setupGoogleSignin() {
try {
await GoogleSignin.hasPlayServices({ autoResolve: true });
await GoogleSignin.hasPlayServices({ autoResolve: true })
await GoogleSignin.configure({
iosClientId,
// webClientId: '603421766430-60og8n04mebic8hi49u1mrcmcdmugnd5.apps.googleusercontent.com',
offlineAccess: false
});
})

const user = await GoogleSignin.currentUserAsync();
console.log(user);
this.setState({user});
const user = await GoogleSignin.currentUserAsync()
const creds = this.props.firebase.auth.GoogleAuthProvider.credential(null, user.accessToken)
await this.props.firebase.auth().signInWithCredential(creds)
}
catch(err) {
console.log("Google signin error", err.code, err.message);
console.log("Google signin error", err.code, err.message)
}
}

_signIn() {
const { auth } = this.props.firebase
return GoogleSignin.signIn()
.then((user) => {
console.log(user);
this.setState({user: user});
const creds = auth.GoogleAuthProvider.credential(null, user.accessToken)
return auth().signInWithCredential(creds)
})
.catch((err) => {
console.log('WRONG SIGNIN', err);
console.error('error authing with firebase:', err)
return Promise.reject(err)
})
}

_signOut() {
return GoogleSignin.revokeAccess()
.then(() => GoogleSignin.signOut())
.then(() => {
this.setState({user: null});
})
.then(() => this.props.firebase.logout())
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

AppRegistry.registerComponent('GoogleSigninSampleApp', () => GoogleSigninSampleApp);
AppRegistry.registerComponent('GoogleSigninSampleApp', () => GoogleSigninSampleApp)

```
2 changes: 2 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { pathToJS, dataToJS, populatedDataToJS } from 'react-redux-firebase'
*None Yet Planned*

#### Features
* Integration for [`react-native-google-signin`](https://github.com/devfd/react-native-google-signin) to simplify react-native authentication implementation
* Nested populates [#85](https://github.com/prescottprue/react-redux-firebase/issues/85)

## Upcoming Major Version (`v2.0.0`)
Expand All @@ -68,6 +69,7 @@ import { pathToJS, dataToJS, populatedDataToJS } from 'react-redux-firebase'
* Improved rendering/update performance for `react` as described in [#84](https://github.com/prescottprue/react-redux-firebase/issues/84)

#### Features
* `react-native` index file referenced in `package.json` that makes it no longer necessary to pass `ReactNative` in config
* `AuthRequired` decorator (or decorator factory) that forces auth to exist before rendering component
* Possibility of delayed initialization as mentioned in [#70](https://github.com/prescottprue/react-redux-firebase/issues/70) (more research needed)

Expand Down
32 changes: 32 additions & 0 deletions examples/complete/react-native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# React Native Complete Example

## Getting Started

**NOTE** This example assumes you have `react-native` installed

1. Clone main repo
1. Enter example folder by running `cd examples/complete/react-native`
1. Install dependencies using `yarn install` or `npm install`
1. Run using `react-native run-ios`

## Dev Scripts
* `npm run dev` - starts watcher and packager together concurrently

## Application Structure

```
.
├─ src # Application source code
│ ├── index.js # Application bootstrap and rendering
│ └── Home.js # Main page
├- ios # Platform specific code, config and dependencies for iOS
│ ├─ GoogleService-info.plist # iOS app config file downloaded from Firebase
├─ scripts # Development helper scripts
│ └── watch-and-copy.js # Development helper that watches and copies changed files
└─ index.ios.js # iOS Application Mounting (connects iOS -> `/src`)
```


## Running Your Own

If you are planning on running your own `react-native` project based on this one. Please make sure you follow the new setup steps in the [react-native recipe](/docs/recipes/react-native.md)
12 changes: 6 additions & 6 deletions examples/complete/react-native/src/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const initialState = { firebase: { authError: null, auth: undefined }}
const store = configureStore(initialState)

const iosClientId = '499842460400-teaflfd8695oilltk5qkvl5688ebgq6b.apps.googleusercontent.com'; // get this from plist file
const webClientId = '603421766430-60og8n04mebic8hi49u1mrcmcdmugnd5.apps.googleusercontent.com';


const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -82,13 +80,12 @@ export default class SigninSampleApp extends Component {
</View>
);
}

// based on google signin example
async _setupGoogleSignin() {
try {
await GoogleSignin.hasPlayServices({ autoResolve: true });
await GoogleSignin.configure({
iosClientId,
webClientId,
offlineAccess: false
});

Expand All @@ -102,12 +99,15 @@ export default class SigninSampleApp extends Component {
}

_signIn() {
const { auth } = this.props.firebase
return GoogleSignin.signIn()
.then((user) => {
const creds = this.props.firebase.auth.GoogleAuthProvider.credential(null, user.accessToken)
return this.props.firebase.auth().signInWithCredential(creds)
const creds = auth.GoogleAuthProvider.credential(null, user.accessToken)
return auth()
.signInWithCredential(creds)
.catch((err) => {
console.error('error authing with firebase:', err)
return Promise.reject(err)
})
})
.catch((err) => {
Expand Down
4 changes: 2 additions & 2 deletions examples/complete/react-native/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createStore, compose } from 'redux'
import rootReducer from './reducer'
import { firebase as fbConfig } from './config'
import { reactReduxFirebase } from 'react-redux-firebase'
import ReactNative from 'react-native'
import { AsyncStorage } from 'react-native'

export default function configureStore (initialState, history) {
const createStoreWithMiddleware = compose(
Expand All @@ -11,7 +11,7 @@ export default function configureStore (initialState, history) {
userProfile: 'users',
enableLogging: false,
enableRedirectHandling: false,
rn: ReactNative,
rn: { AsyncStorage },
}
),
typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
Expand Down
5 changes: 3 additions & 2 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export default (fbConfig, otherConfig) => next =>
}

// Handle react-native
if (configs.rn) {
const { AsyncStorage } = configs.rn
if (configs.ReactNative) {
const { AsyncStorage } = configs.ReactNative
// Stub firebase's internal's with react-native (based on firebase's react-native index file)
firebase.INTERNAL.extendNamespace({
INTERNAL: {
reactNative: {
Expand Down