Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import { Redirect } from 'react-router';
- import AppBar from 'material-ui/AppBar';
- class SignIn extends React.Component{
- constructor(props){
- super(props);
- this.state = {
- redirect: false
- }
- this.onSignIn = this.onSignIn.bind(this)
- this.updateRedirect = this.updateRedirect.bind(this)
- this.test = this.test.bind(this)
- }
- updateLoggedInStatus() {
- gapi.load('auth2', () => {
- gapi.auth2.init({
- client_id: 'ID'
- }).then((auth2) => {
- console.log( "signed in: " + auth2.isSignedIn.get())
- this.setState({
- redirect: auth2.isSignedIn.get()
- })
- })
- })
- }
- updateRedirect() {
- this.setState({
- redirect: true
- })
- }
- componentDidMount() {
- gapi.signin2.render('my-signin2', {
- 'scope': 'profile email',
- 'width': 300,
- 'height': 50,
- 'longtitle': true,
- 'theme': 'dark',
- 'onsuccess': this.onSignIn,
- });
- }
- onSignIn(googleUser) {
- console.log('this ran')
- var profile = googleUser.getBasicProfile();
- console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
- console.log('Name: ' + profile.getName());
- console.log('Image URL: ' + profile.getImageUrl());
- console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
- this.updateRedirect()
- }
- render() {
- const { testRedir } = this.state.redirect
- if (testRedir) {
- return (
- <Redirect to='/options' />
- )
- }
- return (
- <div>
- <AppBar title="Pliny" showMenuIconButton={false} zDepth={2} />
- <div id="my-signin2"></div>
- </div>
- )
- }
- }
- export default SignIn
Add Comment
Please, Sign In to add comment