# Auth Docs

The `auth` package exports one main function: `validateToken`

## `validateToken`

The validateToken function is will take in a string / request or headers object and validate the user auth JWT set by the cloudflare app proxy.

This function ensures that the token included in the request is from a legitimate user. This user's userId is returned in the response.

If the `dontThrow` parameter is specified the function is guaranteed to not throw errors and will instead return `null` if the token is invalid.

It depends on the `@whop-apps/core` package to get the public key and app id from the env.

Required env variables:

- `WHOP_JWT_PK` - the public key to verify JWT. encoded as a JWK
- `NEXT_PUBLIC_WHOP_APP_ID` - the id of the current app.

You can also override both of these in the function arguments

## Errors

all errors thrown by this package are instances of `AuthError` which extends `Error` and has the following properties:

- `code` - the error code (a more machine readable / parse-able version of the error)
