Guest User

Untitled

a guest
Nov 17th, 2017
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. import { Redirect } from 'react-router';
  4. import AppBar from 'material-ui/AppBar';
  5.  
  6.  
  7. class SignIn extends React.Component{
  8.  
  9. constructor(props){
  10. super(props);
  11. this.state = {
  12. redirect: false
  13.  
  14. }
  15. this.onSignIn = this.onSignIn.bind(this)
  16. this.updateRedirect = this.updateRedirect.bind(this)
  17. this.test = this.test.bind(this)
  18. }
  19.  
  20. updateLoggedInStatus() {
  21. gapi.load('auth2', () => {
  22. gapi.auth2.init({
  23. client_id: 'ID'
  24. }).then((auth2) => {
  25. console.log( "signed in: " + auth2.isSignedIn.get())
  26. this.setState({
  27. redirect: auth2.isSignedIn.get()
  28. })
  29. })
  30. })
  31. }
  32.  
  33. updateRedirect() {
  34. this.setState({
  35. redirect: true
  36. })
  37. }
  38.  
  39. componentDidMount() {
  40. gapi.signin2.render('my-signin2', {
  41. 'scope': 'profile email',
  42. 'width': 300,
  43. 'height': 50,
  44. 'longtitle': true,
  45. 'theme': 'dark',
  46. 'onsuccess': this.onSignIn,
  47. });
  48. }
  49.  
  50.  
  51. onSignIn(googleUser) {
  52. console.log('this ran')
  53. var profile = googleUser.getBasicProfile();
  54. console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  55. console.log('Name: ' + profile.getName());
  56. console.log('Image URL: ' + profile.getImageUrl());
  57. console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
  58. this.updateRedirect()
  59. }
  60.  
  61. render() {
  62.  
  63. const { testRedir } = this.state.redirect
  64.  
  65. if (testRedir) {
  66. return (
  67. <Redirect to='/options' />
  68. )
  69. }
  70.  
  71. return (
  72. <div>
  73. <AppBar title="Pliny" showMenuIconButton={false} zDepth={2} />
  74. <div id="my-signin2"></div>
  75. </div>
  76. )
  77. }
  78. }
  79.  
  80. export default SignIn
Add Comment
Please, Sign In to add comment