Skip to content

Commit

Permalink
fix: ext payload should be entirely optional (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jul 15, 2024
1 parent 51da331 commit bfb3ee5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
34 changes: 18 additions & 16 deletions packages/ui/app/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { z } from "zod";
export const FernUserSchema = z.object({
type: z.literal("user"),
partner: z.union([z.literal("workos"), z.literal("ory"), z.literal("custom")]),
name: z.string(),
email: z.string(),
name: z.string().optional(),
email: z.string().optional(),
});

export type FernUser = z.infer<typeof FernUserSchema>;
Expand Down Expand Up @@ -43,24 +43,26 @@ export const OAuthTokenResponseSchema = z.object({

export type OAuthTokenResponse = z.infer<typeof OAuthTokenResponseSchema>;

export const RightbrainUserSchema = z.object({
avatar_url: z.string().optional(),
email: z.string().optional(),
name: z.string().optional(),
org_id: z.string().optional(),
project_id: z.string().optional(),
sso_email_verified: z.boolean().optional(),
});

export const OryAccessTokenSchema = z.object({
aud: z.array(z.string()),
client_id: z.string(),
client_id: z.string().optional(),
exp: z.number().optional(),
ext: z.object({
avatar_url: z.string(),
email: z.string(),
name: z.string(),
org_id: z.string(),
project_id: z.string(),
sso_email_verified: z.boolean(),
}),
iat: z.number(),
iss: z.string(),
jti: z.string(),
nbf: z.number(),
ext: RightbrainUserSchema.optional(),
iat: z.number().optional(),
iss: z.string().optional(),
jti: z.string().optional(),
nbf: z.number().optional(),
scp: z.array(z.string()),
sub: z.string(),
sub: z.string().optional(),
});

export type OryAccessToken = z.infer<typeof OryAccessTokenSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default async function GET(req: NextRequest): Promise<NextResponse> {
const fernUser: FernUser = {
type: "user",
partner: "ory",
name: token.ext.name,
email: token.ext.email,
name: token.ext?.name,
email: token.ext?.email,
};
const expires = token.exp == null ? undefined : new Date(token.exp * 1000);
const res = NextResponse.redirect(redirectLocation);
Expand Down

0 comments on commit bfb3ee5

Please sign in to comment.