Skip to content

Commit b30f7b9

Browse files
committed
allow overriding default allowedRoles
If for e.g. the complete app should be guarded by authentication it's necessary to apply an authenticated role to every route. Signed-off-by: Tobias Kohlbau <[email protected]>
1 parent 2b62b01 commit b30f7b9

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,19 @@ export default {
136136
})
137137
}
138138
};
139-
```
139+
```
140+
141+
### allowedRoles
142+
143+
An array of strings containing the roles allowed to access the app. For e.g. if the app needs to be restrictied it's possible to use a [custom role](https://docs.microsoft.com/en-us/azure/static-web-apps/authentication-authorization).
144+
145+
```js
146+
export default {
147+
kit: {
148+
...
149+
adapter: azure({
150+
allowedRoles: ['authenticated']
151+
})
152+
}
153+
}
154+
```

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type Options = {
66
debug?: boolean;
77
customStaticWebAppConfig?: CustomStaticWebAppConfig;
88
esbuildOptions?: Pick<esbuild.BuildOptions, 'external'>;
9+
allowedRoles?: string[];
910
};
1011

1112
export default function plugin(options?: Options): Adapter;

index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function validateCustomConfig(config) {
2828
export default function ({
2929
debug = false,
3030
customStaticWebAppConfig = {},
31-
esbuildOptions = {}
31+
esbuildOptions = {},
32+
allowedRoles = ['anonymous']
3233
} = {}) {
3334
return {
3435
name: 'adapter-azure-swa',
@@ -48,13 +49,15 @@ export default function ({
4849
{
4950
route: '*',
5051
methods: ['POST', 'PUT', 'DELETE'],
51-
rewrite: ssrFunctionRoute
52+
rewrite: ssrFunctionRoute,
53+
allowedRoles: allowedRoles
5254
},
5355
{
5456
route: `/${builder.config.kit.appDir}/immutable/*`,
5557
headers: {
5658
'cache-control': 'public, immutable, max-age=31536000'
57-
}
59+
},
60+
allowedRoles: allowedRoles
5861
}
5962
],
6063
navigationFallback: {
@@ -130,15 +133,24 @@ export default function ({
130133
swaConfig.routes.push(
131134
{
132135
route: '/index.html',
133-
rewrite: ssrFunctionRoute
136+
rewrite: ssrFunctionRoute,
137+
allowedRoles: allowedRoles
134138
},
135139
{
136140
route: '/',
137-
rewrite: ssrFunctionRoute
141+
rewrite: ssrFunctionRoute,
142+
allowedRoles: allowedRoles
138143
}
139144
);
140145
}
141146

147+
swaConfig.routes.push(
148+
{
149+
route: '*',
150+
allowedRoles: allowedRoles
151+
}
152+
);
153+
142154
writeFileSync(`${publish}/staticwebapp.config.json`, JSON.stringify(swaConfig));
143155
}
144156
};

0 commit comments

Comments
 (0)