You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not currently used in the template but it's basically a sample middleware for you to use in your own server functions. Or you can just delete it and use your own :)
So when you create your own server functions for ur own use cases, you can use that middleware to force server-side authentication for the server fn
e.g.
import{createServerFn}from'@tanstack/start'import{authMiddleware}from'~/lib/middleware/auth-guard'constyourOwnServerFn=createServerFn().middleware([authMiddleware]).handler(async(context)=>{// at this point you can be sure that the user is authenticated// and you can use context.user to access the user dataconsole.log(context.user);})
I should probably work on documenting this or providing a sample server fn that uses this. Thanks for bringing this up.
Reading the TanStack's doc I was a bit confused too to see middleware acting on serverFn only and not routes, need a bit of mental shift form what I've been always used to
I'm seeing
authMiddleware
not being registered anywhere and can't find references of auto imports in the TanStack Router's docs, does it work?The text was updated successfully, but these errors were encountered: