@frigear-nu/authorization 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/app/middleware/authorization.global.js +3 -2
- package/dist/runtime/utils/index.d.ts +1 -0
- package/dist/runtime/utils/index.js +1 -0
- package/dist/runtime/utils/redirect.d.ts +11 -0
- package/dist/runtime/utils/redirect.js +6 -0
- package/package.json +4 -4
package/dist/module.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { evaluateRule, normalizeAuthorizeMeta, resolveRule } from "../../utils/index.js";
|
|
1
|
+
import { evaluateRule, loginRedirect, normalizeAuthorizeMeta, resolveRule } from "../../utils/index.js";
|
|
2
2
|
import { abilities } from "#build/authorization/abilities.mjs";
|
|
3
3
|
import resolveClientUser from "#build/authorization/client-resolver.mjs";
|
|
4
4
|
import { abortNavigation, createError, defineNuxtRouteMiddleware, navigateTo, useRuntimeConfig } from "#imports";
|
|
@@ -11,7 +11,8 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
11
11
|
const response = await evaluateRule(rule, user, abilities);
|
|
12
12
|
if (response.authorized) return;
|
|
13
13
|
if (response.statusCode === 401 && config?.redirectTo) {
|
|
14
|
-
|
|
14
|
+
const target = loginRedirect(config.redirectTo, to.fullPath);
|
|
15
|
+
return navigateTo(target, { external: typeof target === "string" && /^https?:\/\//.test(target) });
|
|
15
16
|
}
|
|
16
17
|
return abortNavigation(createError({ statusCode: response.statusCode ?? 403, message: response.message }));
|
|
17
18
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a guest goes from a page that requires sign in: `redirectTo` with `?redirect=<the page>`, so the sign-in page
|
|
3
|
+
* can send them back (`useAfterLogin` of `@frigear-nu/auth`). Only same-site paths are passed along; an absolute
|
|
4
|
+
* `redirectTo` URL is returned as configured.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loginRedirect(redirectTo: string, fullPath: string): string | {
|
|
7
|
+
path: string;
|
|
8
|
+
query: {
|
|
9
|
+
redirect: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const isInternalPath = (value) => typeof value === "string" && value.startsWith("/") && !value.startsWith("//") && !value.startsWith("/\\");
|
|
2
|
+
export function loginRedirect(redirectTo, fullPath) {
|
|
3
|
+
if (!isInternalPath(redirectTo) || !isInternalPath(fullPath)) return redirectTo;
|
|
4
|
+
if (fullPath.split(/[?#]/)[0] === redirectTo) return redirectTo;
|
|
5
|
+
return { path: redirectTo, query: { redirect: fullPath } };
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/authorization",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Policy-based authorization (abilities, resolvers, route rules, <Can>) for the frigear ecosystem, built on @frigear-nu/users.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/authorization",
|
|
6
6
|
"repository": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"playground"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@frigear-nu/module-kit": "1.1.
|
|
34
|
-
"@frigear-nu/auth": "0.1.
|
|
35
|
-
"@frigear-nu/users": "1.1.
|
|
33
|
+
"@frigear-nu/module-kit": "1.1.3",
|
|
34
|
+
"@frigear-nu/auth": "0.1.4",
|
|
35
|
+
"@frigear-nu/users": "1.1.4",
|
|
36
36
|
"@libsql/client": "^0.18.0",
|
|
37
37
|
"@nuxt/kit": "^4.6.1",
|
|
38
38
|
"drizzle-kit": "^0.31.11",
|