Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing the pop-up Issue on redirection it remain open #20

Open
abdulmajidashraf92 opened this issue Mar 25, 2020 · 10 comments
Open

Closing the pop-up Issue on redirection it remain open #20

abdulmajidashraf92 opened this issue Mar 25, 2020 · 10 comments

Comments

@abdulmajidashraf92
Copy link

abdulmajidashraf92 commented Mar 25, 2020

I'm redirecting but after redirection its remain open how can make it close
<LinkedIn
clientId="1234"
onFailure={this.handleFailure.bind(this)}
onSuccess={this.handleSuccess.bind(this)}
redirectUri="http://localhost:3000/"
scope="w_member_social"
renderElement={({onClick, disabled}) => (
Sign in with
Linkedin
)}>

@nvh95
Copy link
Owner

nvh95 commented Aug 18, 2020

@abdulmajidashraf92 Have you resolved your problem yet? Please note that you need to handle the pop up like one of those demo:
Demo 1: Use react-router-dom
Demo 2: Not use react-router-dom

@trungnguyen269
Copy link

I also had the same problem. And why onSuccess not return something

@aLx450
Copy link

aLx450 commented Sep 18, 2020

Same issue. I used the example with Router.

I get the popup, I can authorize, the code shows up as a URL parameter, but the popup never closes and onSuccess is never called because, I assume, the popup needs to close to do so.

The switch next to the big Linkedin button triggers the popup.

image

image

@ijro
Copy link

ijro commented Nov 27, 2020

Same problem here. @aLx450 did you manage to solve in some way?
I'm using renderElement

<LinkedIn
	clientId="XXXXXXXXXXXXXXXX"
	onFailure={linkedinCallback}
	onSuccess={linkedinCallback}
	scope='r_emailaddress,r_liteprofile'                 
	redirectUri= "http://localhost:3000"  
	renderElement={renderProps => (
		<button href="#" style={styles.linkedinButton} onClick={renderProps.onClick}>
		   <FaLinkedinIn style={styles.nextIcon} size={24} />
		</button>
	)}
/>

@m7amad-7asan
Copy link

This still an issue

@m7amad-7asan
Copy link

@ijro @aLx450 @trungnguyen269 @nvh95 @abdulmajidashraf92
did you find a way to solve this ?

@nvh95
Copy link
Owner

nvh95 commented Nov 21, 2021

In order to make it work, you need to create a route /linkedin and it should be LinkedInCallback. I recommend using react-router-dom as follow:

import React from 'react';
import { LinkedInCallback } from 'react-linkedin-login-oauth2';

import { BrowserRouter, Route, Switch } from 'react-router-dom';

function Demo() {
  return (
    <BrowserRouter>
      // Your `linkedin` callback route
      <Route exact path="/linkedin" component={LinkedInCallback} />
      // Other routes
      ...
    </BrowserRouter>
  );
}

Please refer to Usage to see how to integrate react-linkedin-login-oauth2 to your application. You can find a full example here
Please note that react-linkedin-login-oauth2 is now at version 2.0.0 with some breaking changes. Please refer to Usage or Migration guide from 1 to 2.

@vuyanidaweti
Copy link

carbon

I used Routes and instead of BrowserRoute and it worked

@sebahom
Copy link

sebahom commented Jan 28, 2022

for me

<Route exact path="/linkedin" element={} />

worked. call it as an element instead of a component

@jaredzwick
Copy link

For those still interested, I got it to work by re-implementing the Callback. I'm not sure if there was some changes in v2 or something but I am using react-router-dom v6 with createBrowserRouter and this worked for me:


import { useEffect, useState } from "react";

const LINKEDIN_OAUTH2_STATE = "RANDOM_STR";
function parse(search) {
  const query = search.substring(1);
  const vars = query.split("&");
  const parsed = {};
  for (let i = 0; i < vars.length; i++) {
    const pair = vars[i].split("=");
    if (pair.length > 1) {
      parsed[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
    }
  }
  return parsed;
}

export function CustomCallback() {
  const [errorMessage, setErrorMessage] = useState("");
  useEffect(() => {
    const params = parse(window.location.search);
    console.log(params);
    if (params.error) {
      const errorMessage =
        params.error_description || "Login failed. Please try again.";
      window.opener &&
        window.opener.postMessage(
          {
            error: params.error,
            state: params.state,
            errorMessage,
            from: "Linked In",
          },
          window.location.origin
        );
      // Close tab if user cancelled login
      if (params.error === "user_cancelled_login") {
        window.close();
      }
    }
    if (params.code) {
      window.opener &&
        window.opener.postMessage(
          { code: params.code, state: params.state, from: "Linked In" },
          window.location.origin
        );
    }
  }, []);
  window.close();
  return <div>{errorMessage}</div>;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants