Skip to content

Commit

Permalink
chore(backend): Expose AuthObject type (#3844)
Browse files Browse the repository at this point in the history
Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
kduprey and LekoArts authored Aug 6, 2024
1 parent 9b2aeac commit d7bf0f8
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 38 deletions.
9 changes: 9 additions & 0 deletions .changeset/fast-knives-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@clerk/backend": patch
---

Export the type `AuthObject`. You can now use it like so:

```ts
import type { AuthObject } from "@clerk/backend"
```
10 changes: 10 additions & 0 deletions .changeset/itchy-ravens-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@clerk/clerk-sdk-node": patch
"@clerk/express": patch
"@clerk/fastify": patch
"@clerk/nextjs": patch
"@clerk/astro": patch
"@clerk/remix": patch
---

Internal change: Use `AuthObject` type import from `@clerk/backend`.
10 changes: 2 additions & 8 deletions packages/astro/src/server/clerk-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import type { ClerkClient } from '@clerk/backend';
import type {
AuthenticateRequestOptions,
AuthObject,
ClerkRequest,
RedirectFun,
RequestState,
} from '@clerk/backend/internal';
import type { AuthObject, ClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, ClerkRequest, RedirectFun, RequestState } from '@clerk/backend/internal';
import { AuthStatus, constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { handleValueOrFn, isDevelopmentFromSecretKey, isHttpOrHttps } from '@clerk/shared';
import { eventMethodCalled } from '@clerk/shared/telemetry';
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/server/get-auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type AuthObject, AuthStatus, signedInAuthObject, signedOutAuthObject } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import { AuthStatus, signedInAuthObject, signedOutAuthObject } from '@clerk/backend/internal';
import { decodeJwt } from '@clerk/backend/jwt';
import type { APIContext } from 'astro';

Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ export type {
WebhookEvent,
WebhookEventType,
} from './api/resources/Webhooks';

/**
* Auth objects
*/
export type { AuthObject } from './tokens/authObjects';
7 changes: 1 addition & 6 deletions packages/backend/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export { debugRequestState } from './tokens/request';

export type { AuthenticateRequestOptions } from './tokens/types';

export type {
SignedInAuthObjectOptions,
SignedInAuthObject,
SignedOutAuthObject,
AuthObject,
} from './tokens/authObjects';
export type { SignedInAuthObjectOptions, SignedInAuthObject, SignedOutAuthObject } from './tokens/authObjects';
export { makeAuthObjectSerializable, signedOutAuthObject, signedInAuthObject } from './tokens/authObjects';

export { AuthStatus } from './tokens/authStatus';
Expand Down
2 changes: 1 addition & 1 deletion packages/express/src/__tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthObject } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { Application, Request as ExpressRequest, RequestHandler, Response as ExpressResponse } from 'express';
import express from 'express';
import supertest from 'supertest';
Expand Down
2 changes: 1 addition & 1 deletion packages/express/src/getAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthObject } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { Request as ExpressRequest } from 'express';

import { middlewareRequired } from './errors';
Expand Down
5 changes: 2 additions & 3 deletions packages/express/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, AuthObject } from '@clerk/backend/internal';
import type { AuthObject, createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions } from '@clerk/backend/internal';
import type { Request as ExpressRequest, RequestHandler } from 'express';

export type ExpressRequestWithAuth = ExpressRequest & { auth: AuthObject };
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify/src/getAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthObject } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { FastifyRequest } from 'fastify';

import { pluginRegistrationRequired } from './errors';
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-clerk/src/ssr/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Organization, Session, User } from '@clerk/backend';
import type { AuthenticateRequestOptions, AuthObject } from '@clerk/backend/internal';
import type { AuthObject, Organization, Session, User } from '@clerk/backend';
import type { AuthenticateRequestOptions } from '@clerk/backend/internal';
import type { GetServerDataProps } from 'gatsby';

export type WithServerAuthResult<CallbackReturn> = (props: GetServerDataProps) => Promise<Awaited<CallbackReturn>>;
Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/src/app-router/server/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AuthObject, RedirectFun } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { RedirectFun } from '@clerk/backend/internal';
import { constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { notFound, redirect } from 'next/navigation';

Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AuthenticateRequestOptions, AuthObject, ClerkRequest } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { AuthenticateRequestOptions, ClerkRequest } from '@clerk/backend/internal';
import { AuthStatus, constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
import { eventMethodCalled } from '@clerk/shared/telemetry';
Expand Down
9 changes: 2 additions & 7 deletions packages/nextjs/src/server/clerkMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { AsyncLocalStorage } from 'node:async_hooks';

import type {
AuthenticateRequestOptions,
AuthObject,
ClerkRequest,
RedirectFun,
RequestState,
} from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { AuthenticateRequestOptions, ClerkRequest, RedirectFun, RequestState } from '@clerk/backend/internal';
import { AuthStatus, constants, createClerkRequest, createRedirect } from '@clerk/backend/internal';
import { eventMethodCalled } from '@clerk/shared/telemetry';
import type { NextMiddleware } from 'next/server';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/server/createGetAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AuthObject } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import { AuthStatus, constants, signedInAuthObject, signedOutAuthObject } from '@clerk/backend/internal';
import { decodeJwt } from '@clerk/backend/jwt';

Expand Down
3 changes: 2 additions & 1 deletion packages/nextjs/src/server/protect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AuthObject, RedirectFun, SignedInAuthObject } from '@clerk/backend/internal';
import type { AuthObject } from '@clerk/backend';
import type { RedirectFun, SignedInAuthObject } from '@clerk/backend/internal';
import { constants } from '@clerk/backend/internal';
import type {
CheckAuthorizationParamsWithCustomPermissions,
Expand Down
4 changes: 2 additions & 2 deletions packages/remix/src/ssr/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Organization, Session, User, VerifyTokenOptions } from '@clerk/backend';
import type { AuthObject, RequestState } from '@clerk/backend/internal';
import type { AuthObject, Organization, Session, User, VerifyTokenOptions } from '@clerk/backend';
import type { RequestState } from '@clerk/backend/internal';
import type {
LegacyRedirectProps,
MultiDomainAndOrProxy,
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-node/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, AuthObject, SignedInAuthObject } from '@clerk/backend/internal';
import type { AuthObject, createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, SignedInAuthObject } from '@clerk/backend/internal';
import type { MultiDomainAndOrProxy } from '@clerk/types';
import type { NextFunction, Request, Response } from 'express';
import type { IncomingMessage } from 'http';
Expand Down

0 comments on commit d7bf0f8

Please sign in to comment.