Skip to content

Commit 96ba6fd

Browse files
committed
Convert OAuthMetadata and OAuthTokens to zod
1 parent 8592cf2 commit 96ba6fd

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

client/src/lib/auth.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import pkceChallenge from "pkce-challenge";
22
import { SESSION_KEYS } from "./constants";
3+
import { z } from "zod";
34

4-
export interface OAuthMetadata {
5-
authorization_endpoint: string;
6-
token_endpoint: string;
7-
}
5+
export const OAuthMetadataSchema = z.object({
6+
authorization_endpoint: z.string(),
7+
token_endpoint: z.string()
8+
});
89

9-
export interface OAuthTokens {
10-
access_token: string;
11-
refresh_token?: string;
12-
expires_in?: number;
13-
}
10+
export type OAuthMetadata = z.infer<typeof OAuthMetadataSchema>;
11+
12+
export const OAuthTokensSchema = z.object({
13+
access_token: z.string(),
14+
refresh_token: z.string().optional(),
15+
expires_in: z.number().optional()
16+
});
17+
18+
export type OAuthTokens = z.infer<typeof OAuthTokensSchema>;
1419

1520
export async function discoverOAuthMetadata(
1621
serverUrl: string,
@@ -93,8 +98,7 @@ export async function handleOAuthCallback(
9398
throw new Error("Token exchange failed");
9499
}
95100

96-
const data = await response.json();
97-
return data;
101+
return await response.json();
98102
}
99103

100104
export async function refreshAccessToken(
@@ -122,6 +126,5 @@ export async function refreshAccessToken(
122126
throw new Error("Token refresh failed");
123127
}
124128

125-
const data = await response.json();
126-
return data;
129+
return await response.json();
127130
}

0 commit comments

Comments
 (0)