@mframework/layer-auth 0.0.1
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/app/components/blocks/logoutButton.vue +14 -0
- package/app/composables/useAuth.ts +159 -0
- package/app/composables/useUser.ts +65 -0
- package/app/layouts/auth.vue +8 -0
- package/app/middleware/redirect.global.ts +7 -0
- package/app/middleware/seller.ts +7 -0
- package/app/middleware/session.ts +12 -0
- package/app/module.ts +19 -0
- package/app/pages/callback.vue +22 -0
- package/app/pages/confirm.vue +19 -0
- package/app/pages/forgot-password.vue +156 -0
- package/app/pages/i18n.json +111 -0
- package/app/pages/login.vue +138 -0
- package/app/pages/register.vue +177 -0
- package/app/pages/reset-password.vue +124 -0
- package/app/stores/user.ts +43 -0
- package/app/utils/plugins.ts +24 -0
- package/app/utils/providers/better-auth.ts +125 -0
- package/nuxt.config.ts +18 -0
- package/package.json +30 -0
- package/server/api/auth/[...all].ts +7 -0
- package/server/tsconfig.json +3 -0
- package/server/utils/auth.ts +3 -0
- package/server/utils/query.ts +28 -0
- package/server/utils/require-auth.ts +23 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
// Minimal query utilities shim used by server API endpoints.
|
|
4
|
+
// These are intentionally lightweight to avoid blocking dev flow; replace with
|
|
5
|
+
// full implementations if you need advanced filtering.
|
|
6
|
+
|
|
7
|
+
export const filterSchema = z.array(z.object({
|
|
8
|
+
field: z.string().optional(),
|
|
9
|
+
operator: z.string().optional(),
|
|
10
|
+
value: z.any().optional()
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
export function processFilters(input: any) {
|
|
14
|
+
if (!Array.isArray(input)) return []
|
|
15
|
+
return input
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function withFilters(where: any, filters: any[]) {
|
|
19
|
+
// This shim simply returns the existing where clause. Integrate with your
|
|
20
|
+
// ORM (drizzle) here to transform filters into a proper where expression.
|
|
21
|
+
return where
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
filterSchema,
|
|
26
|
+
processFilters,
|
|
27
|
+
withFilters
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createError, H3Event } from "h3";
|
|
2
|
+
import type { EventHandler } from "h3";
|
|
3
|
+
import { auth } from '@mframework/adapter-betterauth';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Middleware used to require authentication for a route.
|
|
7
|
+
*
|
|
8
|
+
* Can be extended to check for specific roles or permissions.
|
|
9
|
+
*/
|
|
10
|
+
export const requireAuth: EventHandler = async (event: H3Event) => {
|
|
11
|
+
const headers = event.headers;
|
|
12
|
+
|
|
13
|
+
const session = await auth.api.getSession({
|
|
14
|
+
headers: headers,
|
|
15
|
+
});
|
|
16
|
+
if (!session)
|
|
17
|
+
throw createError({
|
|
18
|
+
statusCode: 401,
|
|
19
|
+
statusMessage: "Unauthorized",
|
|
20
|
+
});
|
|
21
|
+
// You can save the session to the event context for later use
|
|
22
|
+
event.context.auth = session;
|
|
23
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"types": ["node", "vitest"],
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"emitDeclarationOnly": false,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"module": "ESNext",
|
|
10
|
+
"target": "ESNext",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"jsx": "react-jsx",
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"noEmitOnError": false
|
|
15
|
+
,
|
|
16
|
+
"paths": {
|
|
17
|
+
"@mframework/adapter-betterauth": ["../../packages/adapters/adapter-betterauth/src/index.ts"],
|
|
18
|
+
"@mframework/adapter-betterauth/*": ["../../packages/adapters/adapter-betterauth/src/*"]
|
|
19
|
+
,
|
|
20
|
+
"@mframework/api": ["../../packages/modules/api/src/index.ts"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|