Full-Stack MSAL (Client + Server) – Discussion & Working Example #6048
DaliborHomola
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone! 👋
I’d like to open a discussion around full-stack MSAL usage (client + server) in TanStack Start.
I couldn't find any complete public example—so here’s my working setup to help others and hopefully spark better ideas.
In my example, I've got:
✅ MSAL on the client (interactive login, Graph calls)
✅ MSAL on the server (server-side validation, protected server functions)
✅ Group-based authorization via Azure AD Groups
This is a long-ish post, but useful for anyone building a full-stack MSAL setup.
Install packages:
npm i @azure/msal-browser @azure/msal-node @azure/msal-react joseLet's start from beggining - wrap the app with MsalProvider and custom navigation
Implementation of MSAL in client
Implementation of MSAL on server. Here you can see we duplicate
msalConfig, but for good reason. The server needs a separatemsalConfigbecause only server code can safely access confidential environment variables.UserProvider: login + loading user profile
User Context
UserHooks
We are going to finish now, let's implement TanStack Start middleware
And the usage is simple as that
Known limitation:
serverFnAccessTokenMiddlewareandauthenticationMiddlewarecannot be applied globally insrc/start.tsbecause they would run during SSR — before the user is initialized. Still looking for a clean workaround.beforeLoadon the server side.Beta Was this translation helpful? Give feedback.
All reactions