Getting started
Authentication
Resources
- Access Passes
- Attachments
- Authentication
- Chats
- Direct Messages
- Experiences
- Forums
- Notifications
- Payments
- Users
Authentication
Retrieve current user
Retrieve the public profile information for the currently logged in user
// app/experiences/[experienceId]/page.tsx
import { whopApi } from "@/lib/whop-api";
import { headers } from "next/headers";
const headersList = await headers();
// Extract the user ID (this will extract the user ID from the headers for you)
const { userId } = await verifyUserToken(headersList);
// Load the user's public profile information
const user = (await whopApi.retrieveUser({userId: userId})).publicUser;
console.log(user);
Not using the Whop TS SDK?
In order to retrieve the current user’s ID, you need to decrypt a JWT token that is stored in the x-whop-user-token
header. VerifyUserToken
is a helper function in our TS SDK that decodes the JWT token and returns the user’s ID.
If are using a different framework and do not have access to the Typescript Whop SDK, you will need to implement your own JWT decoding logic. Here is an example of how to do this in Ruby on Rails:
Ruby on Rails
require 'jwt'
require 'openssl'
# This is a static public key that is used to decode the JWT token
# You can put this into your application
JWT_PEM = <<~PEM.freeze
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAErz8a8vxvexHC0TLT91g7llOdDOsN
uYiGEfic4Qhni+HMfRBuUphOh7F3k8QgwZc9UlL0AHmyYqtbhL9NuJes6w==
-----END PUBLIC KEY-----
PEM
# In your controller
user_token = request.headers["x-whop-user-token"]
return if user_token.blank?
key = OpenSSL::PKey::EC.new(JWT_PEM)
payload, _header = JWT.decode user_token, key, true, {
iss: "urn:whopcom:exp-proxy",
verify_iss: true,
algorithm: "ES256"
}
jwt_app_id = payload["aud"]
# WARNING! You must set the WHOP_APP_ID environment variable in your application.
# This looks like app_xxxx.
return if jwt_app_id != ENV.fetch("WHOP_APP_ID")
jwt_user_id = payload["sub"]
Was this page helpful?
On this page
Assistant
Responses are generated using AI and may contain mistakes.