Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using passport-google-oauth with react-native

I'm trying to use passport-google-oauth in my react-native application. When I run the app it throws the error: requiring unknown module util . I've installed the package using npm install .. and I've also tried npm install ... --save

App/Components/Login.js

'use strict';

var React = require('react-native');
var GoogleStrategy = require('passport-google-oauth').OAuthStrategy;
...

package.json

{
  "name": "NativeApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node_modules/react-native/packager/packager.sh"
  },
  "dependencies": {
    "passport": ">= 0.0.0",
    "passport-google-oauth": "^0.2.0",
    "react-native": "^0.4.4"
  },
  "devDependencies": {}
}

index.ios.js

'use strict';

var React = require('react-native');
var Login = require('./App/Components/login');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  NavigatorIOS,
} = React;

class AppStoreIOS extends React.Component{
  render() {
    return (
      <NavigatorIOS
        titleTextColor = '#0073A0'
        // barTintColor = '#183E63'
        initialRoute={{
          component: Login,
          title: 'AppStore v2.0',
          passProps: { myProp: 'foo' },
        }}
      />
    );
  }
};
like image 653
Antarr Byrd Avatar asked May 15 '26 10:05

Antarr Byrd


1 Answers

Don't think this going to work for you. Passport expects to be run in an node.js (express based) environment, and will at least require some work to port it to using a webview for the Oauth flow, realistically it will be a lot of work.

Have a look at https://medium.com/@jtremback/oauth-2-with-react-native-c3c7c64cbb6d for an example of how to support oauth in react-native. I haven't tried this, but it looks pretty straight forward.

like image 67
deanmcpherson Avatar answered May 18 '26 02:05

deanmcpherson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!