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:
Wuesteon 2025-12-16 02:43:55 +01:00
parent eeab9b7fea
commit 26ca921158
9 changed files with 513 additions and 32 deletions

View 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';

View file

@ -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';