@mframework/layer-auth 0.0.1 → 0.0.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.
@@ -0,0 +1,8 @@
1
+ export interface MeeoviCustomerGroup {
2
+ id: string
3
+ name: string
4
+ description?: string | null
5
+ memberIds?: string[]
6
+ metadata?: Record<string, unknown>
7
+ }
8
+
@@ -0,0 +1,47 @@
1
+ export interface MeeoviUser {
2
+ instance_id?: string | null
3
+ id: string
4
+ aud?: string | null
5
+ role?: string | null
6
+ email?: string | null
7
+ encrypted_password?: string | null
8
+ email_confirmed_at?: string | null
9
+ invited_at?: string | null
10
+ confirmation_token?: string | null
11
+ confirmation_sent_at?: string | null
12
+ recovery_token?: string | null
13
+ recovery_sent_at?: string | null
14
+ email_change_token_new?: string | null
15
+ email_change?: string | null
16
+ email_change_sent_at?: string | null
17
+ last_sign_in_at?: string | null
18
+ raw_app_meta_data?: Record<string, unknown> | null
19
+ raw_user_meta_data?: Record<string, unknown> | null
20
+ is_super_admin?: boolean | null
21
+ created_at?: string | null
22
+ updated_at?: string | null
23
+ phone?: string | null
24
+ phone_confirmed_at?: string | null
25
+ phone_change?: string | null
26
+ phone_change_token?: string | null
27
+ phone_change_sent_at?: string | null
28
+ confirmed_at?: string | null
29
+ email_change_token_current?: string | null
30
+ email_change_confirm_status?: number | null
31
+ banned_until?: string | null
32
+ reauthentication_token?: string | null
33
+ reauthentication_sent_at?: string | null
34
+ is_sso_user?: boolean
35
+ deleted_at?: string | null
36
+ is_anonymous?: boolean
37
+ identities?: Record<string, unknown>[]
38
+ mfa_factors?: Record<string, unknown>[]
39
+ oauth_authorizations?: Record<string, unknown>[]
40
+ oauth_consents?: Record<string, unknown>[]
41
+ one_time_tokens?: Record<string, unknown>[]
42
+ sessions?: Record<string, unknown>[]
43
+ emoji_reactions?: Record<string, unknown>[]
44
+ profiles?: Record<string, unknown> | null
45
+ }
46
+
47
+
@@ -1,20 +1,8 @@
1
- import type {
2
- Subscription
3
- } from '@better-auth/stripe'
4
- import type {
5
- CustomerState
6
- } from '@polar-sh/sdk/models/components/customerstate.js'
7
- import type {
8
- BetterAuthClientOptions,
9
- InferSessionFromClient,
10
- User
11
- } from 'better-auth/client'
12
- import {
13
- createAuthClient
14
- } from 'better-auth/client'
15
- import {
16
- getAuthPlugins
17
- } from '../utils/plugins'
1
+ import type { Subscription } from '@better-auth/stripe'
2
+ import type { CustomerState } from '@polar-sh/sdk/models/components/customerstate.js'
3
+ import type { BetterAuthClientOptions, InferSessionFromClient, User } from 'better-auth/client'
4
+ import { createAuthClient } from 'better-auth/client'
5
+ import { getAuthPlugins } from '../utils/plugins'
18
6
 
19
7
  export type UseAuthOptions = {
20
8
  /** An existing auth client. If provided, it's used as-is. */
@@ -41,29 +29,50 @@ export function useAuth(options: UseAuthOptions = {}) {
41
29
  reload
42
30
  } = options
43
31
 
44
- const client = providedClient || createAuthClient({
45
- baseURL: baseURL || undefined,
46
- fetchOptions: {
47
- headers
48
- },
49
- socialProviders: {
50
- github: {
51
- clientId: process.env.GITHUB_CLIENT_ID!,
52
- clientSecret: process.env.GITHUB_CLIENT_SECRET!
53
- },
54
- microsoft: {
55
- clientId: process.env.MICROSOFT_CLIENT_ID!,
56
- clientSecret: process.env.MICROSOFT_CLIENT_SECRET!
57
- },
58
- twitter: {
59
- clientId: process.env.TWITTER_CLIENT_ID!,
60
- clientSecret: process.env.TWITTER_CLIENT_SECRET!
32
+ // Resolve a client in this order:
33
+ // 1. providedClient (explicit)
34
+ // 2. adapter provider (if adapter-betterauth is present)
35
+ // 3. local createAuthClient fallback
36
+ let client: any = providedClient || null
37
+
38
+ if (!client) {
39
+ // Attempt to use adapter registry/provider if available
40
+ try {
41
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
42
+ const adapter = require('@mframework/adapter-betterauth')
43
+ if (adapter && typeof adapter.getAuthProvider === 'function') {
44
+ const prov = adapter.getAuthProvider()
45
+ // Wrap provider methods into a minimal client-like interface
46
+ client = {
47
+ async getSession() {
48
+ const s = await prov.session()
49
+ return { data: { session: s, user: (s && s.user) || null } }
50
+ },
51
+ signIn: prov.login?.bind(prov),
52
+ signUp: prov.register?.bind(prov),
53
+ signOut: prov.logout?.bind(prov),
54
+ refresh: prov.refresh?.bind(prov),
55
+ subscription: { list: async () => ({ data: [] }) },
56
+ $ERROR_CODES: {},
57
+ }
61
58
  }
62
- },
63
- plugins: getAuthPlugins({
64
- subscription: true
59
+ } catch (e) {
60
+ // adapter-betterauth not available — fall back to client library below
61
+ }
62
+ }
63
+
64
+ if (!client) {
65
+ client = createAuthClient({
66
+ baseURL: baseURL || undefined,
67
+ fetchOptions: { headers },
68
+ socialProviders: {
69
+ github: { clientId: process.env.GITHUB_CLIENT_ID!, clientSecret: process.env.GITHUB_CLIENT_SECRET! },
70
+ microsoft: { clientId: process.env.MICROSOFT_CLIENT_ID!, clientSecret: process.env.MICROSOFT_CLIENT_SECRET! },
71
+ twitter: { clientId: process.env.TWITTER_CLIENT_ID!, clientSecret: process.env.TWITTER_CLIENT_SECRET! }
72
+ },
73
+ plugins: getAuthPlugins({ subscription: true })
65
74
  })
66
- })
75
+ }
67
76
 
68
77
  let session: InferSessionFromClient < BetterAuthClientOptions > | null = null
69
78
  let user: User | null = null
@@ -0,0 +1,7 @@
1
+ import { AuthSession } from "./session"
2
+
3
+ export interface AuthAdapter {
4
+ getSession(): Promise<AuthSession | null>
5
+ signIn(email: string, password: string): Promise<AuthSession>
6
+ signOut(): Promise<void>
7
+ }
@@ -0,0 +1,7 @@
1
+ export interface User {
2
+ id?: string
3
+ first_name?: string
4
+ last_name?: string
5
+ email?: string
6
+ [key: string]: any
7
+ }
@@ -0,0 +1,33 @@
1
+ import { z } from 'zod'
2
+
3
+ export const LoginInputSchema = z.object({
4
+ email: z.string().email(),
5
+ password: z.string().min(8)
6
+ })
7
+
8
+ export type LoginInput = z.infer<typeof LoginInputSchema>
9
+
10
+ export const RegisterInputSchema = z.object({
11
+ email: z.string().email(),
12
+ password: z.string().min(8),
13
+ confirmPassword: z.string().min(8)
14
+ }).refine((data) => data.password === data.confirmPassword, {
15
+ message: 'Passwords do not match',
16
+ path: ['confirmPassword']
17
+ })
18
+
19
+ export type RegisterInput = z.infer<typeof RegisterInputSchema>
20
+
21
+ export const ForgotPasswordInputSchema = z.object({
22
+ email: z.string().email()
23
+ })
24
+
25
+ export type ForgotPasswordInput = z.infer<typeof ForgotPasswordInputSchema>
26
+
27
+ export const ResetPasswordInputSchema = z.object({
28
+ token: z.string(),
29
+ password: z.string().min(8),
30
+ confirmPassword: z.string().min(8)
31
+ })
32
+
33
+ export type ResetPasswordInput = z.infer<typeof ResetPasswordInputSchema>
@@ -0,0 +1,6 @@
1
+ export interface OAuthProvider {
2
+ id: string
3
+ label: string
4
+ icon?: string
5
+ authUrl: string
6
+ }
@@ -0,0 +1,8 @@
1
+ import { AuthUser } from "./user"
2
+
3
+ export interface AuthSession {
4
+ user: AuthUser | null
5
+ accessToken: string | null
6
+ refreshToken?: string | null
7
+ expiresAt?: number
8
+ }
@@ -0,0 +1,4 @@
1
+ declare module '@mframework/api' {
2
+ export const prisma: any
3
+ export default prisma
4
+ }
@@ -0,0 +1,9 @@
1
+ export interface AuthUser {
2
+ id: string
3
+ email: string
4
+ name?: string
5
+ avatarUrl?: string
6
+ emailVerified: boolean
7
+ createdAt: string
8
+ updatedAt: string
9
+ }
@@ -1,24 +1,42 @@
1
- import { stripeClient } from '@better-auth/stripe/client'
2
- import { polarClient, adminClient, inferAdditionalFields } from '@mframework/adapter-betterauth/'
3
-
4
- export type AuthPluginOptions = {
5
- /** whether to enable subscription support for stripe plugin */
6
- subscription?: boolean
7
- }
1
+ export type AuthPluginOptions = { subscription?: boolean }
8
2
 
9
3
  export function getAuthPlugins(opts: AuthPluginOptions = {}): any[] {
10
4
  const { subscription = true } = opts
11
5
 
12
- return [
13
- inferAdditionalFields({
14
- user: {
15
- polarCustomerId: {
16
- type: 'string'
17
- }
18
- }
19
- }),
20
- adminClient(),
21
- polarClient(),
22
- stripeClient({ subscription })
23
- ]
6
+ const plugins: any[] = []
7
+
8
+ // Try to load adapter-provided plugin helpers when available, otherwise
9
+ // return an empty plugin list (safer for build-time without adapters).
10
+ try {
11
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
12
+ const adapter = require('@mframework/adapter-betterauth')
13
+ const inferAdditionalFields = adapter.inferAdditionalFields || adapter.default?.inferAdditionalFields
14
+ const adminClient = adapter.adminClient || adapter.default?.adminClient
15
+ const polarClient = adapter.polarClient || adapter.default?.polarClient
16
+
17
+ if (inferAdditionalFields) {
18
+ plugins.push(
19
+ inferAdditionalFields({
20
+ user: { polarCustomerId: { type: 'string' } }
21
+ })
22
+ )
23
+ }
24
+
25
+ if (adminClient) plugins.push(adminClient())
26
+ if (polarClient) plugins.push(polarClient())
27
+ } catch (e) {
28
+ // adapter not present — ignore
29
+ }
30
+
31
+ // Try to load stripe client plugin separately
32
+ try {
33
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
34
+ const stripe = require('@better-auth/stripe/client')
35
+ const stripeClient = stripe?.stripeClient || stripe?.default || stripe
36
+ if (typeof stripeClient === 'function') plugins.push(stripeClient({ subscription }))
37
+ } catch (e) {
38
+ // stripe plugin not available — ignore
39
+ }
40
+
41
+ return plugins
24
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mframework/layer-auth",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "The authentication layer for M Framework applications.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -19,7 +19,6 @@
19
19
  "author": "M Framework",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@mframework/adapter-betterauth": "^0.0.7",
23
22
  "typescript": "^5.9.3"
24
23
  },
25
24
  "devDependencies": {
package/tsconfig.json CHANGED
@@ -5,12 +5,15 @@
5
5
  "declaration": true,
6
6
  "emitDeclarationOnly": false,
7
7
  "outDir": "dist",
8
- "moduleResolution": "bundler",
9
8
  "module": "ESNext",
10
- "target": "ESNext",
9
+ "target": "ES2017",
10
+ "moduleResolution": "bundler",
11
+ "esModuleInterop": true,
12
+ "allowSyntheticDefaultImports": true,
13
+ "lib": ["ES2017", "DOM"],
11
14
  "strict": true,
12
15
  "jsx": "react-jsx",
13
- "skipLibCheck": true,
16
+ "skipLibCheck": true,
14
17
  "noEmitOnError": false
15
18
  ,
16
19
  "paths": {
@@ -20,4 +23,13 @@
20
23
  "@mframework/api": ["../../packages/modules/api/src/index.ts"]
21
24
  }
22
25
  }
26
+ ,
27
+ "exclude": [
28
+ "node_modules",
29
+ "dist"
30
+ ],
31
+ "include": [
32
+ "app/**/*",
33
+ "server/**/*"
34
+ ]
23
35
  }