How to get properly userId from strapi when login?

user8282183292

I am migrating from strapi 3.6.8 (mongodb-mongo cluster) to 4.2 (mysql -azuremysql) with React native Expo CLI, I am testing this new version locally but I have this error when i login and try to get auth data from user i dont receive idUser only token. The interesting part is when I refresh the app (not clossing session) and go to Account Screen I can finally get idUser if I close session and login with another user, have same problem.

This is where i try to get idUser (Account Screen)

import useAuth from "../../Hooks/useAuth";
export default function Account() {
  const [user, setUser] = useState(null);
  const { auth } = useAuth();
  console.log(auth);
  useFocusEffect(
    useCallback(() => {
      (async () => {
        const response = await getMeApi(auth.token);
        setUser(response);
      })();
    }, [])
  );

This is useAuth (just a bridge between AuthContext and other components)

import { useContext } from "react";
import AuthContext from "../Context/AuthContext";

export default () => useContext(AuthContext);

This is AuthContext

import { createContext } from "react";

const AuthContext = createContext({
  auth: undefined,
  login: () => null,
  logout: () => null,
});

export default AuthContext;

This is what i have printing auth enter image description here

Sjouke

Your setUser(response); call takes in a response from the Strapi User Permissions provider which looks something like this:

data : {
  user: {
    ...
  },
  jwt: ...
}

https://docs.strapi.io/developer-docs/latest/plugins/users-permissions.html#login.

Trying to access idUser on this object is not defined.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Codeigniter how to get userid after login

How to get UserId from localStorage

Asp Core Identity, How to get userId after login?

How to decode jwt and get from this userId in feathersjs?

How to get userId from database without Auth::()?

WebAPI - How to get UserID from token

how to get userId from token in django

How to get the current UserId from Firestore?

How to get UserID from ASP.NET Identity when sending Rest Request

How to properly get url for the login view in template?

Get userID from database

How to get userId as ClientId?

How to get an Alexa userId?

Login with UserSettingsFragment, get UserID and replace Fragment then

How to get the DataSource, UserID and Password from an Entity ConnectionString?

How to get userid in angular view from Spring Boot REST Controller

how to get user object by userid from result of aggregation

how to get userid and password from database and pass to Method in Spring MVC

How to get userId from access token for Gmail OAuth2.0

How to get Google UserId from active user session in App Maker?

how to get values based on userid from firebase database using flutter

How to get firebase userID from inside a firebase cloud function

How to get specific values from all UserID (UID) and save in RecyclerViewFirebaseUI

Discord.py: How do I get a user from a UserID?

How to get userid from a string in discord.py

How do I pass a UserID from State into a GET URL

get UserId when the button is clicked

Instagram get username from userId

Get username from userid in a view