1

I am using React component for OAuth GitHub login in my web site. Here is the npm link : https://www.npmjs.com/package/github-login

But I am unable to extract the user details from that response object. When I console log the response this is the output. It does not contain any user details at all.

{code: "9f2ed749b2a26236e367"}

This is my component

import React, { Component } from "react";

import "materialize-css/dist/css/materialize.min.css";
import GitHubLogin from "github-login";

class Github extends Component {
  state = {
    isLoggedIn: false,
    userID: "",
    name: "",
    email: "",
    picture: "",
  };

  onSuccess = (response) => {
    this.setState({
      isLoggedIn: true,
      userID: response.userID,
      name: response.name.split(" ")[0],
      email: response.email,
      picture: response.picture.data.url,
    });
    console.log(response);
  };

onFailure = (response) => console.error(response);

  render() {
    let gitContent;

    if (this.state.isLoggedIn) {

      sessionStorage.setItem("userName", this.state.name);
      sessionStorage.setItem("userPhoto", this.state.picture);

    } else {
      gitContent = (
        <GitHubLogin
          clientId="Iv1.11fe935eb08a191a"
          redirectUri="https://noobstack.netlify.app/"
          onSuccess={this.onSuccess}
          onFailure={this.onFailure}
          className="github-button"
        />
      );
    }
    return <div>{gitContent}</div>;
  }
}

export default Github;

I did the exact same thing to Facebook login, It works fine. But in GitHub login response object does not contain any user data. How do I extract user data from the response object?

4

0 回答 0