Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ Additionally there are packages which act as shared utilities or building blocks
## Setup
- Clone the repository.
- `npm install`.
- `npm run build`.

\* See the [docs folder](./docs) for additional repository documentation.
5 changes: 4 additions & 1 deletion packages/backend-core/src/api/ClerkBackendAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ type ClerkBackendAPIProps = {
serverApiUrl?: string;
/* Backend API version */
apiVersion?: string;
/* HTTP fetch implementation (not specific to window.fetch API) */
/*
* HTTP fetch implementation (not specific to window.fetch API).
* The fetcher implementation should return the response body, not the whole response.
*/
fetcher: ClerkFetcher;
/* Library/SDK name */
libName: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/backend-core/src/api/utils/RestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ type RequestOptions = {
bodyParams?: object;
};

/*
* HTTP fetch implementation (not specific to window.fetch API).
* The fetcher implementation should return the response body, not the whole response.
*/
export type ClerkFetcher = (
url: string,
options: {
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk-node/examples/express/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CLERK_API_KEY=test_foo
CLERK_API_URL=https://api.clerk.dev
CLERK_LOGGING=false
PORT=5000
1 change: 1 addition & 0 deletions packages/sdk-node/examples/express/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3,557 changes: 3,557 additions & 0 deletions packages/sdk-node/examples/express/package-lock.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions packages/sdk-node/examples/express/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "clerk-sdk-node-express-example",
"dependencies": {
"@clerk/clerk-sdk-node": "file:../../dist",
"dotenv": "latest",
"express": "latest"
},
"devDependencies": {
"@types/express": "^4.17.13",
"nodemon": "^2.0.14",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
},
"scripts": {
"tsc": "tsc",
"start": "nodemon src/server.ts"
}
}
34 changes: 34 additions & 0 deletions packages/sdk-node/examples/express/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
ClerkExpressRequireSession,
ClerkExpressWithSession,
WithSessionProp,
} from '@clerk/clerk-sdk-node';
import dotenv from 'dotenv';
import express, { Application, Request, Response } from 'express';
dotenv.config();

const port = process.env.PORT;

const app: Application = express();

// Root path uses lax middleware
app.get(
'/',
ClerkExpressWithSession(),
(req: WithSessionProp<Request>, res: Response) => {
res.json(req.session || 'No session detected');
}
);

// /require-session path uses strict middleware
app.get(
'/require-session',
ClerkExpressRequireSession(),
(req: WithSessionProp<Request>, res) => {
res.json(req.session);
}
);

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
33 changes: 33 additions & 0 deletions packages/sdk-node/examples/express/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"include": ["src"],
"compilerOptions": {
"module": "CommonJS",
"lib": ["dom", "esnext"],
"importHelpers": true,
// output .d.ts declaration files for consumers
"declaration": true,
// output .js.map sourcemap files for consumers
"sourceMap": true,
// match output dir to input dir. e.g. dist/index instead of dist/src/index
"rootDir": "./src",
// stricter type-checking for stronger correctness. Recommended by TS
"strict": true,
// linter checks for common issues
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
// noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative
"noUnusedLocals": true,
"noUnusedParameters": true,
// use Node's module resolution algorithm, instead of the legacy TS one
"moduleResolution": "node",
// transpile JSX to React.createElement
"jsx": "react",
// interop between ESM and CJS modules. Recommended by TS
"esModuleInterop": true,
// error out if import and file system have a casing mismatch. Recommended by TS
"forceConsistentCasingInFileNames": true,
// `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc`
"noEmit": true,
"target": "ES5"
}
}
3 changes: 3 additions & 0 deletions packages/sdk-node/examples/next/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLERK_API_KEY=test_foo
CLERK_API_URL=https://api.clerk.dev
CLERK_LOGGING=false
34 changes: 34 additions & 0 deletions packages/sdk-node/examples/next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
34 changes: 34 additions & 0 deletions packages/sdk-node/examples/next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/import?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Loading