const AUTH0_CLIENT_ID = "aIAOt9fkMZKrNsSsFqbKj5KTI0ObTDPP"; const AUTH0_DOMAIN = "hakaselabs.auth0.com"; const AUTH0_CALLBACK_URL = location.href; const AUTH0_API_AUDIENCE = "golang-gin"; class App extends React.Component { parseHash() { this.auth0 = new auth0.WebAuth({ domain: AUTH0_DOMAIN, clientID: AUTH0_CLIENT_ID }); this.auth0.parseHash(window.location.hash, (err, authResult) => { if (err) { return console.log(err); } if ( authResult !== null && authResult.accessToken !== null && authResult.idToken !== null ) { localStorage.setItem("access_token", authResult.accessToken); localStorage.setItem("id_token", authResult.idToken); localStorage.setItem( "profile", JSON.stringify(authResult.idTokenPayload) ); window.location = window.location.href.substr( 0, window.location.href.indexOf("#") ); } }); } setup() { $.ajaxSetup({ beforeSend: (r) => { if (localStorage.getItem("access_token")) { r.setRequestHeader( "Authorization", "Bearer " + localStorage.getItem("access_token") ); } } }); } setState() { //let idToken = localStorage.getItem("id_token"); let idToken = true; if (idToken) { this.loggedIn = true; } else { this.loggedIn = false; } } componentWillMount() { this.setup(); this.parseHash(); this.setState(); } render() { if (this.loggedIn) { return ; } return ; } } class Home extends React.Component { constructor(props) { super(props); this.authenticate = this.authenticate.bind(this); } authenticate() { this.WebAuth = new auth0.WebAuth({ domain: AUTH0_DOMAIN, clientID: AUTH0_CLIENT_ID, scope: "openid profile", audience: AUTH0_API_AUDIENCE, responseType: "token id_token", redirectUri: AUTH0_CALLBACK_URL }); this.WebAuth.authorize(); } render() { return (

MyApp

A load of Properties

Sign in to get access

Sign In
); } } class LoggedIn extends React.Component { constructor(props) { super(props); this.state = { listings: [] }; this.serverRequest = this.serverRequest.bind(this); this.logout = this.logout.bind(this); } logout() { localStorage.removeItem("id_token"); localStorage.removeItem("access_token"); localStorage.removeItem("profile"); location.reload(); } serverRequest() { $.get("http://localhost:3000/api/v1/listing", res => { this.setState({ listings: res }); }); } componentDidMount() { this.serverRequest(); } render() { return (

Log out

MyApp

Let's feed you with some Properties!!!

{this.state.listings.map(function(listing, i) { return ; })}
); } } class Listing extends React.Component { constructor(props) { super(props); this.state = { liked: "", listings: [] }; this.like = this.like.bind(this); this.serverRequest = this.serverRequest.bind(this); } like() { let listing = this.props.listing; this.serverRequest(listing); } serverRequest(listing) { $.post( "http://localhost:3000/api/v1/listing/like/" + listing.Listing_Id, { like: 1 }, res => { console.log("res... ", res); this.setState({ liked: "Liked!", listings: res }); this.props.listings = res; } ); } render() { return (
${this.props.listing.Price}
{this.props.listing.Street1}{" "} {this.props.listing.Street2}{", "} {this.props.listing.City}{" "} {this.props.listing.State} {this.state.liked}
{this.props.listing.Description}
{this.props.listing.Likes} Likes  
); } } ReactDOM.render(, document.getElementById("app"));