Skip to content

Commit

Permalink
attempt to get id directly from token
Browse files Browse the repository at this point in the history
  • Loading branch information
artlu99 committed Nov 3, 2024
1 parent d905e33 commit 789a1a7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions functions/getSassyHashes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,25 @@ interface SassyHashRequest {
castHash: string;
}

const getFid = async (privyAuthToken: string, env: Env): Promise<number> => {
const getPrivyIdToken = async (cookies: string | undefined) => {
if (!cookies) return null;
const privyIdToken = cookies.match(/privy_id_token=(?<privyIdToken>.*)/)?.groups?.privyIdToken;
if (!privyIdToken) return null;
return privyIdToken;
};

const getFid = async (privyAuthToken: string, context): Promise<number> => {
const { env, request } = context;
const privy = new PrivyClient(env.REACT_APP_PRIVY_APP_ID, env.PRIVY_APP_SECRET);

const cookies = request.headers.get('cookie');

const privyIdToken = await getPrivyIdToken(cookies);
console.log('privyIdToken:', privyIdToken);

const user = await privy.getUser({ idToken: privyIdToken });
console.log('user:', user);

try {
const verifiedClaims = await privy.verifyAuthToken(privyAuthToken);
const user = await privy.getUser(verifiedClaims.userId);
Expand Down Expand Up @@ -65,10 +81,7 @@ export const onRequestPost: PagesFunction<Env> = async (context) => {
const js = (await request.json()) as SassyHashRequest;
const { privyAuthToken, castHash } = js;

const cookies: string = request.headers.get('cookie');
console.log('cookies:', cookies);

const fid = await getFid(privyAuthToken, env);
const fid = await getFid(privyAuthToken, context);
if (!fid) return new Response(JSON.stringify({ error: 'Failed to fetch Farcaster FID' }), { status: 500 });

const sassyHashResponses = await fetchSassyHashExpensiveApi(fid, castHash, env);
Expand Down

0 comments on commit 789a1a7

Please sign in to comment.