Skip to content

Commit ba404be

Browse files
Copilothotlong
andcommitted
Address code review feedback - improve type safety and error handling
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a8b552b commit ba404be

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/adapter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface ObjectQLAdapterConfig {
2828
export function createObjectQLAdapter(config: ObjectQLAdapterConfig) {
2929
const { ql, debugLogs = false } = config;
3030

31-
return (options: BetterAuthOptions) => {
31+
return (_options: BetterAuthOptions) => {
3232
// Model name mapping (better-auth uses lowercase model names)
3333
const modelMap: Record<string, string> = {
3434
user: 'User',

src/client/hooks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ export type ObjectStackClientSession = {
8585
export function usePermissions() {
8686
const { data: session, isPending } = useSession();
8787

88+
// Safely extract permissions, defaulting to undefined if not present
89+
const permissions = session?.user && 'permissions' in session.user
90+
? (session.user as any).permissions
91+
: undefined;
92+
8893
return {
89-
permissions: (session?.user as any)?.permissions as string[] | Record<string, boolean> | null | undefined,
94+
permissions,
9095
isPending,
9196
isAuthenticated: !!session,
9297
};

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export function createAuthPlugin(config: AuthPluginConfig = {}): ObjectStackPlug
101101
// Better-Auth exposes a handler for all auth routes
102102
// The handler expects a Web Request object
103103
context.app.all('/api/auth/*', async (req: any) => {
104-
return authServer!.handler(req);
104+
if (!authServer) {
105+
throw new Error('Auth server not initialized');
106+
}
107+
return authServer.handler(req);
105108
});
106109

107110
console.log('[Auth Plugin] Authentication routes registered at /api/auth/*');

src/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function createAuthServer(config: ObjectStackAuthServerConfig) {
8484
}
8585

8686
// Add social providers if configured
87-
if (socialProviders && typeof socialProviders === 'object' && Object.keys(socialProviders).length > 0) {
87+
if (socialProviders && Object.keys(socialProviders).length > 0) {
8888
authOptions.socialProviders = socialProviders as BetterAuthOptions['socialProviders'];
8989
}
9090

0 commit comments

Comments
 (0)