Full-Stack MSAL (Client + Server) – Discussion & Working Example #6048
DaliborHomola
started this conversation in
General
Replies: 1 comment 1 reply
-
|
@DaliborHomola Did you find any workaround? |
Beta Was this translation helpful? Give feedback.
1 reply
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 v5 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
✅ Perform permission checks in
beforeLoadroute propThis 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 - load user into router context and wrap app with provider
Implementation of MSAL in client
The server needs a separate
msalConfigbecause only server code can safely access confidential environment variables.Define Types
Now the Provider
We are going to finish now, let's implement TanStack Start middleware
And last thing: configuration and helpers
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.Beta Was this translation helpful? Give feedback.
All reactions