-
Notifications
You must be signed in to change notification settings - Fork 460
feat(backend,clerk-sdk-node): Simplify the authenticateRequest signature #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@clerk/clerk-sdk-node': patch | ||
| '@clerk/backend': patch | ||
| --- | ||
|
|
||
| Simplify the signature of the low-level `authenticateRequest` helper. | ||
| - One pair of legacy or new instance keys are required instead of all 4 of them in `authenticateRequest` | ||
| - `@clerk/backend` now can handle the `"Bearer "` prefix in Authorization header for better DX | ||
| - `host` parameter is now optional in `@clerk/backend` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,9 +40,59 @@ export type OptionalVerifyTokenOptions = Partial< | |
| > | ||
| >; | ||
|
|
||
| export type AuthenticateRequestOptions = RequiredVerifyTokenOptions & | ||
| type PublicKeys = | ||
| | { | ||
| publishableKey: string; | ||
| /** | ||
| * @deprecated Use `publishableKey` instead. | ||
| */ | ||
| frontendApi: never; | ||
| } | ||
| | { | ||
| publishableKey: never; | ||
| /** | ||
| * @deprecated Use `publishableKey` instead. | ||
| */ | ||
| frontendApi: string; | ||
| } | ||
| | { | ||
| publishableKey: string; | ||
| /** | ||
| * @deprecated Use `publishableKey` instead. | ||
| */ | ||
| frontendApi: string; | ||
|
Comment on lines
+59
to
+63
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can we have both?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have wayy more context that me here so please ignore if it doesn't make sense, however, the usual way to write this would be: type ExclusiveAOrB = {
a: string;
b?: never;
} | {
a?: never;
b: string;
}(notice the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@nikosdouvlis Isn't this a breaking change (on the type-level) of anyone passing both? |
||
| }; | ||
|
|
||
| type SecretKeys = | ||
| | { | ||
| secretKey: string; | ||
| /** | ||
| * @deprecated Use `secretKey` instead. | ||
| */ | ||
| apiKey: never; | ||
| } | ||
| | { | ||
| secretKey: never; | ||
| /** | ||
| * @deprecated Use `secretKey` instead. | ||
| */ | ||
| apiKey: string; | ||
| } | ||
| | { | ||
| secretKey: string; | ||
| /** | ||
| * @deprecated Use `secretKey` instead. | ||
| */ | ||
| apiKey: string; | ||
| }; | ||
|
|
||
| export type InstanceKeys = PublicKeys & SecretKeys; | ||
|
|
||
| export type AuthenticateRequestOptions = InstanceKeys & | ||
| OptionalVerifyTokenOptions & | ||
| LoadResourcesOptions & { | ||
| apiVersion?: string; | ||
| apiUrl?: string; | ||
| /* Client token cookie value */ | ||
| cookieToken?: string; | ||
| /* Client uat cookie value */ | ||
|
|
@@ -51,12 +101,8 @@ export type AuthenticateRequestOptions = RequiredVerifyTokenOptions & | |
| headerToken?: string; | ||
| /* Request origin header value */ | ||
| origin?: string; | ||
| /* Clerk frontend Api value */ | ||
| frontendApi: string; | ||
| /* Clerk Publishable Key value */ | ||
| publishableKey: string; | ||
| /* Request host header value */ | ||
| host: string; | ||
| host?: string; | ||
| /* Request forwarded host value */ | ||
| forwardedHost?: string; | ||
| /* Request forwarded port value */ | ||
|
|
@@ -105,6 +151,7 @@ export async function authenticateRequest(options: AuthenticateRequestOptions): | |
| options.frontendApi = parsePublishableKey(options.publishableKey)?.frontendApi || options.frontendApi || ''; | ||
| options.apiUrl = options.apiUrl || API_URL; | ||
| options.apiVersion = options.apiVersion || API_VERSION; | ||
| options.headerToken = options.headerToken?.replace('Bearer ', ''); | ||
|
|
||
| assertValidSecretKey(options.secretKey || options.apiKey); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.