(req)
| 6 | ); |
| 7 | |
| 8 | async function getUserFromToken(req) { |
| 9 | try { |
| 10 | const authToken = req.cookies.get("privy-token")?.value; |
| 11 | if (!authToken) { |
| 12 | throw new Error("No ID token found in cookies"); |
| 13 | } |
| 14 | const verifiedClaims = await privy.verifyAuthToken(authToken); |
| 15 | const user = await privy.getUserById(verifiedClaims.userId); |
| 16 | return user; |
| 17 | } catch (error) { |
| 18 | console.error("Error validating ID token:", error); |
| 19 | throw new Error("Invalid or expired token"); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | export { getUserFromToken, privy }; |