Back

LinkedIn OAuth successful login but get session returns 401

  • 0
  • Accounts
  • Web
Eddie Jaoude | EddieHub
24 Jan, 2024, 15:20

I can log in successful via LinkedIn OAuth and redirected back the successful url, and the user appears in Appwrite Cloud Auth section but getSession("current") throws a 401

Steps to reproduce...

  1. click login
  2. redirected to LinkedIn and login
  3. redirected to successul url on my app
  4. use getSession("current") throws a 401
TypeScript
const getAppwriteUser = async () => {
    let session = {};
    try {
      session = await account.getSession("current");
      let linkedinUser = {};
      if (session) {
        // fake data, get real profile info from LinkedIn
        linkedinUser = {
          imageUrl: "https://github.com/eddiejaoude.png",
          name: "TEST",
          email: "email TEST",
        };
      }
      setUser(linkedinUser);
    } catch (e) {
      console.log(e);
      setUser(null);
    }
  };

  useEffect(() => {
    getAppwriteUser();
  }, []);

Console error

TypeScript
Failed to load resource: the server responded with a status of 401 ()
TL;DR
Title: LinkedIn OAuth successful login, but `getSession("current")` returns 401 In this support thread, a developer successfully logs in with LinkedIn OAuth and is redirected back to their application. The user's LinkedIn profile is also created in Appwrite Cloud. However, when attempting to retrieve the current session using `getSession("current")`, the developer encounters a 401 error. To resolve this issue, the developer should check if the OAuth2 session for LinkedIn was created properly and verify that the session token is being sent correctly to the backend. Additionally, it's important to ensure that the backend is properly configured to handle the LinkedIn OAuth flow
Kenny
24 Jan, 2024, 15:26

What does your code for authenticating look like?

Eddie Jaoude | EddieHub
24 Jan, 2024, 15:27
TypeScript
   const login = async () => {
    account.createOAuth2Session(
      "linkedin",
      `${process.env.NEXT_PUBLIC_BASE_URL}/success`,
      `${process.env.NEXT_PUBLIC_BASE_URL}/failure`
    );
  };
Eddie Jaoude | EddieHub
24 Jan, 2024, 15:32

I am able to log in on LinkedIn and redirected back to /success and my user was created in Appwrite Cloud

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more