Forum Discussion

Sameerr's avatar
Sameerr
Copper Contributor
Jun 04, 2025

React and MSAL No active account found for Graph API after login Ensuring Account Readiness

Hi everyone,

My React app uses Microsoft's MSAL library for user login. After login, it needs to show SharePoint images (like thumbnails in a table) using the Microsoft Graph API.

The Problem:
Often, right after a user logs into my app (using the Microsoft login popup), when my app tries to get these SharePoint images, I get a "No active account found" error. It seems like MSAL doesn't have an active user account ready for the Graph API call at that exact moment, even though MSAL itself says the user is logged in and that it isn't busy with other login tasks. This usually happens when the page first tries to show these images immediately after the login finishes.

An Important Clue:
I found something interesting: if the user first opens any SharePoint site in their browser (like in another tab) and then uses or refreshes my React app, the images load perfectly without any error. This makes me think it's a timing problem – my app might be trying to get the images too quickly after login, before the browser's connection to SharePoint is fully ready for my app to make requests via the Graph API.

I am trying to make my app wait for MSAL to completely finish its setup, and I also double-check that MSAL has an active user account before I ask for the images. But, the error can still happen if the user hasn't done that manual SharePoint visit first.

My Question:
What's the best way in a React app (using MSAL) to reliably make sure that everything is truly ready – both the MSAL login being complete AND my app being able to successfully use the Graph API for SharePoint resources – immediately after a user logs in? I want users to see the images straight away without needing to manually open SharePoint first for the images in my app to work.

Any tips or advice on how to best handle this "not quite ready yet" timing with MSAL and SharePoint would be a huge help!

Thanks!

No RepliesBe the first to reply

Resources