Get User session data

System Information
  • Strapi Version: ^4.24.5
  • Operating System: Windows
  • Database: Postgress
  • Node Version: >=18.0.0 <=20.x.x
  • NPM Version: >=6.0.0
  • Yarn Version:

Hi all, this may very well be a silly question but here goes…

When a User logs into the backend Dashboard, I’m assuming there’s a session or a JWT token etc??

I’d like to get it and use it as a Bearer token to Authourize a fetch call.

How do I do this?

I found a solution although I’m not sure how robust it is.

You need to do an import:
import { auth } from "@strapi/helper-plugin";

Then you can call the auth.getUserInfo() function to see information about who’s logged in.

You can also call auth.getToken() and other useful functions.

Console.log(auth) to see a full list of options.