mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-18 02:29:41 +02:00
✨ feat(auth): add centralized @manacore/better-auth-types package
Create new shared package for Better Auth type definitions: - UserRole, JWTPayload, CurrentUserData types - Type guards: isValidUserRole, isValidOrganizationRole - Utility functions: jwtPayloadToCurrentUser - userAdditionalFields for client type inference Migrate shared packages to use centralized types: - @manacore/shared-auth re-exports from new package - @manacore/shared-nestjs-auth uses new package as dependency
This commit is contained in:
parent
eeab9b7fea
commit
26ca921158
9 changed files with 513 additions and 32 deletions
35
packages/shared-auth/src/better-auth-fields.ts
Normal file
35
packages/shared-auth/src/better-auth-fields.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Better Auth Additional Field Definitions
|
||||
*
|
||||
* Re-exports centralized types from @manacore/better-auth-types.
|
||||
* This file is provided for convenience when importing from @manacore/shared-auth.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // In SvelteKit/React app
|
||||
* import { createAuthClient } from "better-auth/client";
|
||||
* import { inferAdditionalFields } from "better-auth/client/plugins";
|
||||
* import { userAdditionalFields } from "@manacore/shared-auth";
|
||||
*
|
||||
* export const authClient = createAuthClient({
|
||||
* baseURL: "http://localhost:3001",
|
||||
* plugins: [inferAdditionalFields(userAdditionalFields)],
|
||||
* });
|
||||
*
|
||||
* // Now user.role is properly typed!
|
||||
* const session = await authClient.getSession();
|
||||
* console.log(session?.user.role); // TypeScript knows this is string
|
||||
* ```
|
||||
*
|
||||
* @see https://www.better-auth.com/docs/concepts/typescript
|
||||
*/
|
||||
|
||||
// Re-export from centralized package
|
||||
export {
|
||||
userAdditionalFields,
|
||||
type UserRole,
|
||||
type OrganizationRole,
|
||||
type UserWithAdditionalFields,
|
||||
isValidUserRole,
|
||||
isValidOrganizationRole,
|
||||
} from '@manacore/better-auth-types';
|
||||
|
|
@ -1,6 +1,16 @@
|
|||
// Types
|
||||
export * from './types';
|
||||
|
||||
// Better Auth field definitions for client type inference
|
||||
export {
|
||||
userAdditionalFields,
|
||||
type UserRole,
|
||||
type OrganizationRole,
|
||||
type UserWithAdditionalFields,
|
||||
isValidUserRole,
|
||||
isValidOrganizationRole,
|
||||
} from './better-auth-fields';
|
||||
|
||||
// Core utilities
|
||||
import { createAuthService as _createAuthService } from './core/authService';
|
||||
export { createAuthService } from './core/authService';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue