Skip to content

Commit

Permalink
feat: refactor custom framework utils to reuse them (#933)
Browse files Browse the repository at this point in the history
* Add init util methods for custom framework support

* Add some more changes for the custom framework re-usability

* Expose custom framework

* Update changelog and bump version

* Add a fix for accessing SessionRecipe

* Add init tests for the custom framework implementation

* Update some variable names to match the custom framework definition

* Add more tests for custom framework regarding withSession

* Add tests for getSessionForSSR

* Fix mochar related config and command

* Add init changes to re-use functionality from custom framework in next

* Fix export name for customframework and version

* Add support for re-using duplicated code in nextjs from customframework

* Reuse even more code from customframework into next.js

* Reuse a customError handler in next

* Update customFramework to handle JWT verification manually

* Use internal functions for jwt parsing

* Add a fix for accessing nextjs cookie extractor

* Reuse an util function for getting JWK's

* Reuse more functionality from custom framework in next

* Add a comment about acceptin jwks as a parameter for getSessionForSSR

* several fixes and refactoring

* Fix custom framework related tests

* Add/fix tests for next js

* Add test for session refresh in next

* Add test for core being down and error handler called in next

* Add detail of breaking change in changelog

* Adds migration guide for using updated next.js handler function

---------

Co-authored-by: rishabhpoddar <[email protected]>
  • Loading branch information
deepjyoti30-st and rishabhpoddar authored Oct 7, 2024
1 parent 1da2d3c commit 0e21e6d
Show file tree
Hide file tree
Showing 14 changed files with 1,180 additions and 723 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a way to run CI on unmerged PRs
- Added support for FDIs: 3.1 and 4.0. Required by: auth-react >=0.49.0 and web-js>=0.15.0
- The `networkInterceptor` now also gets a new `params` prop in the request config.
- Adds `customFramework` util functions to minimize code required in custom frameworks like remix, astro etc.
- Replicates `fastify` types based on requirement for the SDK instead of using the original module.

### Breaking change
Expand Down Expand Up @@ -50,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- This means that we removed `override.openIdFeature` from the Session recipe configuration
- Removed `getJWKS` from the OpenId recipe, as it is already exposed by the JWT recipe
- We now automatically initialize the OpenId and JWT recipes even if you do not use the Session recipe
- `getAppDirRequestHandler` for `nextjs` will no longer accept a Response object.

### Migration

Expand Down Expand Up @@ -140,6 +142,25 @@ SuperTokens.init({
});
```

#### Using updated `getAppDirRequestHandler` for next.js

Before:

```ts
import { getAppDirRequestHandler } from "supertokens-node/nextjs";
import { NextResponse } from "next/server";

const handleCall = getAppDirRequestHandler(NextResponse);
```

After:

```ts
import { getAppDirRequestHandler } from "supertokens-node/nextjs";

const handleCall = getAppDirRequestHandler();
```

## [20.1.3] - 2024-09-30

- Replaces `psl` with `tldts` to avoid `punycode` deprecation warning.
Expand Down
11 changes: 11 additions & 0 deletions custom/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * from "../lib/build/customFramework";
/**
* 'export *' does not re-export a default.
* import CustomFramework from "supertokens-node/custom";
* the above import statement won't be possible unless either
* - user add "esModuleInterop": true in their tsconfig.json file
* - we do the following change:
*/

import * as _default from "../lib/build/customFramework";
export default _default;
6 changes: 6 additions & 0 deletions custom/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
__export(require("../lib/build/customFramework"));
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getAppDirRequestHandler } from "supertokens-node/nextjs";
import { NextRequest, NextResponse } from "next/server";
import { NextRequest } from "next/server";
import supertokens from "supertokens-node";
import { backendConfig } from "../../../../config/backendConfig";

supertokens.init(backendConfig());

const handleCall = getAppDirRequestHandler(NextResponse);
const handleCall = getAppDirRequestHandler();

export async function GET(request: NextRequest) {
const res = await handleCall(request);
Expand Down
60 changes: 60 additions & 0 deletions lib/build/customFramework.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

208 changes: 208 additions & 0 deletions lib/build/customFramework.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions lib/build/nextjs.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e21e6d

Please sign in to comment.