How to get access token and social media id from auth0 in nextjs application

Viewed 142

I'm trying to get access token and id token from auth0 login

The useUser hook only returning the user info, while I want to get access token and social media id of user which I want to send to my own custom php api to get user data and validate on my own database,

Kindly help me on this problem and suggest some good approaches according to you

here's my login page code:

import React from "react";
import { useUser} from "@auth0/nextjs-auth0";


const login = () => {
  const { user, isLoading, error } = useUser();
  //all user data here, with tokens

  console.log(user);
  return (
    <div>
      <div className="contentContainer">
        <div className="contentRight">
          <div
            style={{
              display: "flex",
              alignItems: "center",
              justifyContent: "center",
              flexDirection: "column",
              height: "100vh",
              width: "100vw",
            }}
          >
            {user ? (
              <div style={{ display: "flex", flexDirection: "column" }}>
                <a href="/api/auth/logout">Sign Out</a>{" "}
                <img src={user.picture} alt="" />
                <h1>{user.name}</h1>
              </div>
            ) : (
              <a href="/api/auth/login">Sign in</a>
            )}
          </div>
        </div>
      </div>
    </div>
  );
};

export default login;
1 Answers

Hope you are doing well. Please refer to this article:- https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/#Next-js-Static-Site-Approach Check the section of useSWR hook. Hope that solves the problem. Other than that - the code you have written in stack overflow - please add of react-router-dom, instead of tag, because tag refreshes the whole page every time. You can refer:- https://v5.reactrouter.com/web/guides/quick-start Feel free to contact me if you have any doubts regarding this.

Related