question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MSAL in Storybook

See original GitHub issue

Core Library

MSAL.js v2 (@azure/msal-browser)

Core Library Version

2.19.0

Wrapper Library

MSAL React (@azure/msal-react)

Wrapper Library Version

1.1.1

Description

I’m Trying to set up MSAL in Storybook using a decorator, https://storybook.js.org/docs/react/writing-stories/decorators

It works fine on pageload and if refresh the page, but if i click between the stories I can see that “inProgress” is “startup” and nothing else happens.

I have tried with different configurations for cache, but to no avail.

Anyone got any tips or have done this themself?

I reckon it is something on Storybooks side and how they handle routing as it the same configration i use for the other apps and they work fine.

I dont want to add MSALProvider for each story

MSAL Configuration

auth: {
    clientId: xxx,
    authority: xxx,
    redirectUri: '/',
  },
  cache: {
    secureCookies: true,
    cacheLocation: 'localStorage', // This configures where your cache will be stored
    storeAuthStateInCookie: true, // Set this to "true" if you are having issues on IE11 or Edge
  },

Relevant Code Snippets

./storybook/preview.js

const withMSALProvider = (Story) => {
  return (
    <MsalProvider instance={publicClientApplication}>
      <MsalAuthenticationTemplate
        interactionType={InteractionType.Popup}
        loadingComponent={InProgressComponent}
        errorComponent={ErrorComponent}
      >
        <Story />
      </MsalAuthenticationTemplate>

      <UnauthenticatedTemplate>
        <LoggInn />
      </UnauthenticatedTemplate>
    </MsalProvider>
  );
};

export const decorators = [withMSALProvider];

Identity Provider

Azure AD / MSA

Source

External (Customer)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tnorlingcommented, Dec 3, 2021

This issue will be fixed by the linked PR. Thanks for bringing this to our attention!

1reaction
igoroviccommented, Nov 30, 2021

I was able to workaround this issue with this code.

function MyApp({ Component, pageProps }: AppProps) {
  return <Component {...pageProps} />;
}

const App2 = appWithTranslation(MyApp);

function MsalApp(props: AppProps) {
  const router = useRouter();
  const navigationClient = new CustomNavigationClient(router);
  msalInstance.setNavigationClient(navigationClient);
  return (
    <MsalProvider instance={msalInstance}>
      <App2 {...props} />
    </MsalProvider>
  );
}

export default MsalApp;

@tnorling Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auth - Page ⋅ Storybook - Introduction
Provides the ability to restrict contents based on clientId (e.g. restrict content if the user is not authenticated against clientId). For base usage,...
Read more >
Add Auth to a Storybook project - Stack Overflow
I'd want to use authentication in my Storybook project (my preferred auth provider being Auth0). Is there any add-on that could help me...
Read more >
Getting started / Recommended libraries - Page ⋅ Storybook
microsoft-authentication-library-for-js msal-react is a library which provides Azure Active Directory Library (ADAL) support for React.
Read more >
Overview - Page ⋅ Storybook
Uses msal-browser to sign in users and acquire tokens in Microsoft Teams tabs. Supports Single Sign-On with custom backend. TeamsFx, Use the TeamsFx...
Read more >
Testing component interactions - Storybook - Medium
This is an email from Storybook news, a newsletter by Storybook. ... Azure AD authentication in angular using MSAL angular v2 library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found