Skip to content

Instantly share code, notes, and snippets.

@joeflack4
Last active November 8, 2019 08:43
Show Gist options
  • Save joeflack4/4b271a33a072ad097150374dfa304a68 to your computer and use it in GitHub Desktop.
Save joeflack4/4b271a33a072ad097150374dfa304a68 to your computer and use it in GitHub Desktop.
Cannot read property 'isAvailable' of undefined
import auth0 from 'auth0-js';
import Auth0Cordova from '@auth0/cordova';
import React, { Component } from 'react';
import {Tabbar, Tab} from 'react-onsenui';
import DataEntryPage from './pages/DataEntryPage';
import HomePage from './pages/HomePage';
import PersonalPage from './pages/PersonalPage';
export default class App extends Component {
auth0 = new auth0.Authentication({
domain: 'fakeDomain.auth0.com',
clientID: 'this_is_a_fake_id_for_purposes_of_this_gist'
});
state = {
authenticated: false,
accessToken: false,
}
login(e) {
e.target.disabled = true;
var client = new Auth0Cordova({
domain: 'fakeDomain.auth0.com',
clientId: 'this_is_a_fake_id_for_purposes_of_this_gist',
packageIdentifier: 'net.fake.something'
});
var options = {
scope: 'openid profile',
audience: 'https://fakeDomain.auth0.com/userinfo'
};
var self = this;
client.authorize(options, function(err, authResult) {
if (err) {
console.log(err);
return (e.target.disabled = false);
}
localStorage.setItem('access_token', authResult.accessToken);
self.resumeApp();
});
};
logout(e) {
localStorage.removeItem('access_token');
this.resumeApp();
};
loadProfile(cb) {
this.auth0.userInfo(this.state.accessToken, cb);
};
static resumeApp() {
var accessToken = localStorage.getItem('access_token');
if (accessToken) {
this.setState({
authenticated: true,
accessToken: accessToken
});
} else {
this.setState({
authenticated: false,
accessToken: null
});
}
};
static run() {
this.resumeApp();
};
static renderTabs() {
return [
{
content: <HomePage key={'home'} {...this.props} login={e => this.login(e)} logout={e => this.logout(e)} />,
tab: <Tab key='home' label='' icon='fa-home' />
},
{
content: <DataEntryPage key={'data-entry'} {...this.props} />,
tab: <Tab key='data-entry' label='' icon='fa-clipboard' />
},
{
content: <PersonalPage key={'personal'} {...this.props} />,
tab: <Tab key='personal' label='' icon='fa-user-circle' />
}
]
}
render() {
return (
<Tabbar {...this.props} initialIndex={0} renderTabs={App.renderTabs}
login={e => this.login(e)}
logout={e => this.logout(e)} />
);
}
}
import React from 'react';
import {Button, Page, Toolbar} from 'react-onsenui';
export default class HomePage extends React.Component {
loggedIn = false ? true : false;
username = 'SomeUser';
render() {
return (
<Page
renderToolbar={() =>
<Toolbar>
<div className='center' style={{textAlign: 'center'}}>Glaucoma Tracker</div>
</Toolbar>
}
>
<br/><br/>
<section style={{textAlign: 'center'}}>
<p>No data has yet been entered.</p>
<p>To start recording data, click select the 'form' button from the bottom.</p>
</section>
<br/>
<section style={{textAlign: 'center'}}>{this.loggedIn
? <React.Fragment>
<p>You are logged in.</p>
<p><Button onClick={e => this.props.logout(e)}>Logout</Button></p>
</React.Fragment>
: <React.Fragment>
<p>You are not logged in.</p>
<p><Button onClick={e => {
this.props.login(e)
}}>Login</Button></p>
</React.Fragment>
}</section>
</Page>
);
}
}
import Auth0Cordova from '@auth0/cordova';
import React from 'react';
import ReactDOM from 'react-dom';
import 'onsenui/css/onsenui.css';
import 'onsenui/css/onsen-css-components.css';
import App from './App';
const intentHandler = (url) => {
Auth0Cordova.onRedirectUri(url);
}
window.handleOpenURL = intentHandler;
const appProps = {};
const app = <App props={appProps} />;
ReactDOM.render(app, document.getElementById('root'));
document.addEventListener('deviceready', app)
{
"name": "joeflack4-test-app-01",
"version": "1.1.0",
"description": "",
"private": true,
"dependencies": {
"@auth0/cordova": "^0.3.0",
"auth0-js": "^9.7.3",
"cordova-custom-config": "5.0.2",
"cordova-plugin-customurlscheme": "^4.3.0",
"cordova-plugin-safariviewcontroller": "^1.5.4",
"cordova-plugin-splashscreen": "5.0.1",
"cordova-plugin-whitelist": "1.3.3",
"input-moment": "^0.4.0",
"moment": "^2.22.2",
"monaca-plugin-monaca-core": "3.2.0",
"onsenui": "~2.10.0",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-onsenui": "~1.11.0",
"react-scripts": "1.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"cordova": {
"plugins": {
"cordova-custom-config": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-whitelist": {},
"monaca-plugin-monaca-core": {},
"cordova-plugin-safariviewcontroller": {},
"cordova-plugin-customurlscheme": {
"URL_SCHEME": "{net.fake.Domain}",
"ANDROID_SCHEME": "{net.fake.Domain}",
"ANDROID_HOST": "fakeDomain.auth0.com}",
"ANDROID_PATHPREFIX": "/cordova/{net.fake.Domain}/callback"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment