Skip to content

Commit e27c258

Browse files
committed
docs: more practical example for static assets restriction
1 parent f11a9e3 commit e27c258

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

docs/topics/startup.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ app.UseViteStaticFiles();
9494

9595
``` c#
9696
// With custom authorization:
97-
app.UseViteStaticFiles(new ViteStaticFilesOptions
97+
app.UseViteStaticFiles(new()
9898
{
99-
OnAuthorizeAsync = async ctx =>
100-
{
101-
if (ctx.Context.User?.Identity?.IsAuthenticated == true) return true;
102-
// Return false to deny access to specific files.
103-
// You can control file names with `manualChunks` in vite.config.ts.
104-
return !ctx.File.Name.Contains("private");
105-
}
99+
OnAuthorizeAsync = ctx => ctx.Context.Request.Path.StartsWithSegments("/assets") == true
100+
// Vite compiled assets require authentication
101+
? ValueTask.FromResult(ctx.Context.User.Identity?.IsAuthenticated == true)
102+
// Anything else (e.g. `arc/public` directory) do not.
103+
: ValueTask.FromResult(true)
106104
});
107105
```
108106

0 commit comments

Comments
 (0)