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

after login its not calling onSuccess function #62

Open
zafarhussain633 opened this issue Mar 13, 2022 · 6 comments
Open

after login its not calling onSuccess function #62

zafarhussain633 opened this issue Mar 13, 2022 · 6 comments

Comments

@zafarhussain633
Copy link

No description provided.

@tleopardt
Copy link

I'm also having this problem in the latest version, I already allow linkedin login but it didn't call onSuccess function so it returns nothing. Please somebody help

@devnexitus
Copy link

Hello, I'm having a similar issue. But it's only happening on localhost, when i deploy my app to some server this error happens. It executes onError all the time and redirects to the redirectUri with no params which causes LinkedInCallback component always shows "state does not match".

Is there a way to fix this?

@zafarhussain633
Copy link
Author

i think this package have some serious issue

@nvh95
Copy link
Owner

nvh95 commented Jun 11, 2022

Hi @zafarhussain633, @tleopardt, @devnexitus,

Thank you for reaching us.

Did you setup LinkedInCallback using react-router-dom or Next.js's file system routing as mentioned in Usage (https://github.com/nvh95/react-linkedin-login-oauth2#usage)?

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

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

function Demo() {
  return (
    <BrowserRouter>
      <Route exact path="/linkedin" component={LinkedInCallback} />
    </BrowserRouter>
  );
}
// pages/linkedin.js
import { LinkedInCallback } from 'react-linkedin-login-oauth2';
export default function LinkedInPage() {
  return <LinkedInCallback />;
}

If you follow the Usage and still experience any issues. Please help to create a minimal reproduction so we can support you. Thanks.

@kpruban98
Copy link

Hello, I'm having a similar issue. But it's only happening on localhost, when i deploy my app to some server this error happens. It executes onError all the time and redirects to the redirectUri with no params which causes LinkedInCallback component always shows "state does not match".

Is there a way to fix this?

Facing same issue, any luck finding the solution?

@jay-klavans
Copy link

Hello!

I have solved this problem by making the modal by myself.

I used local storage to communicate between parent and child window as childWindow.opener is null if origin is different.

const width = 500;
const height = 600;
const left = window.screen.width / 2 - width / 2;
const top = window.screen.height / 2 - height / 2;
const params = width=${width},height=${height},left=${left},top=${top};

let url = new URL("https://www.linkedin.com/oauth/v2/authorization")
url.searchParams.append('response_type', 'code')
url.searchParams.append('client_id', linkedInClientId)
url.searchParams.append('redirect_uri', ${window.location.origin}/linkedin)
url.searchParams.append('scope', 'r_emailaddress r_liteprofile')

const popup = window.open(url, 'LinkedIn Login', params);

const handleInvalidToken = e => {
if (e.key === 'linkedin_login_code') {
popup.close();
dispatch(linkedinLoginAction(e.newValue, navigate));
}
}
window.addEventListener('storage', handleInvalidToken)

Make new route component yourself and add it to your route...

import { useEffect } from "react";

export default function LinkedinCallback(props) {

useEffect(() => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const code = urlParams.get('code');
localStorage.setItem('linkedin_login_code', code)
window.close()
}, [])

return <></>
}

Thank you.

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

6 participants