Skip to content

Commit

Permalink
chore: Merge release into main (#13481)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF authored Jun 7, 2024
2 parents 211a7ec + dc9b8ee commit d93b687
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/api/modules/_aws_amplify_adapter_nextjs.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@aws-amplify/adapter-nextjs - v1.2.3 | Amplify JS API Documentation</title><meta name="description" content="Documentation for Amplify JS API Documentation"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><link rel="stylesheet" href="../assets/custom.css"/><script defer src="../assets/main.js"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script><link rel="icon" href="../favicon.ico" />
</head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"><a href="https://docs.amplify.aws/">Library Documentation</a><a href="https://www.npmjs.com/package/aws-amplify">NPM</a><a href="https://github.com/aws-amplify/amplify-js">GitHub</a></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">Amplify JS API Documentation</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../index.html">Amplify JS API Documentation</a></li><li><a href="_aws_amplify_adapter_nextjs.html">@aws-amplify/adapter-nextjs</a></li></ul><h1>Module @aws-amplify/adapter-nextjs - v1.2.3</h1></div><section class="tsd-panel tsd-typography"><p>This package contains the AWS Amplify Next.js Adapter. For more information on using Next.js in your application please reference the <a href="https://docs.amplify.aws/javascript/build-a-backend/server-side-rendering/nextjs/">Amplify Dev Center</a>.</p>
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>@aws-amplify/adapter-nextjs - v1.2.4 | Amplify JS API Documentation</title><meta name="description" content="Documentation for Amplify JS API Documentation"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><link rel="stylesheet" href="../assets/custom.css"/><script defer src="../assets/main.js"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script><link rel="icon" href="../favicon.ico" />
</head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"><a href="https://docs.amplify.aws/">Library Documentation</a><a href="https://www.npmjs.com/package/aws-amplify">NPM</a><a href="https://github.com/aws-amplify/amplify-js">GitHub</a></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">Amplify JS API Documentation</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../index.html">Amplify JS API Documentation</a></li><li><a href="_aws_amplify_adapter_nextjs.html">@aws-amplify/adapter-nextjs</a></li></ul><h1>Module @aws-amplify/adapter-nextjs - v1.2.4</h1></div><section class="tsd-panel tsd-typography"><p>This package contains the AWS Amplify Next.js Adapter. For more information on using Next.js in your application please reference the <a href="https://docs.amplify.aws/javascript/build-a-backend/server-side-rendering/nextjs/">Amplify Dev Center</a>.</p>
</section><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><h3 class="tsd-index-heading uppercase">Index</h3><section class="tsd-index-section"><h3 class="tsd-index-heading">Modules</h3><div class="tsd-index-list"><a href="_aws_amplify_adapter_nextjs.api.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2"></use></svg><span>api</span></a>
<a href="_aws_amplify_adapter_nextjs.index.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2"></use></svg><span>index</span></a>
<a href="_aws_amplify_adapter_nextjs.utils.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-2"></use></svg><span>utils</span></a>
Expand Down
4 changes: 4 additions & 0 deletions packages/adapter-nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.2.4](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/adapter-nextjs@1.2.3...@aws-amplify/adapter-nextjs@1.2.4) (2024-06-07)

**Note:** Version bump only for package @aws-amplify/adapter-nextjs

## [1.2.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/adapter-nextjs@1.2.2...@aws-amplify/adapter-nextjs@1.2.3) (2024-06-07)

**Note:** Version bump only for package @aws-amplify/adapter-nextjs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CognitoJwtVerifier } from 'aws-jwt-verify';
import { JwtExpiredError } from 'aws-jwt-verify/error';

import { isValidCognitoToken } from '../../src/utils/isValidCognitoToken';

Expand Down Expand Up @@ -45,6 +46,31 @@ describe('isValidCognitoToken', () => {
expect(mockVerifier.verify).toHaveBeenCalledWith(token);
});

it('should return true for a token that has valid signature and expired', async () => {
const mockVerifier: any = {
verify: jest
.fn()
.mockRejectedValue(
new JwtExpiredError('Token expired', 'mocked-token'),
),
};
mockedCreate.mockReturnValue(mockVerifier);

const isValid = await isValidCognitoToken({
token,
userPoolId,
clientId,
tokenType,
});
expect(isValid).toBe(true);
expect(CognitoJwtVerifier.create).toHaveBeenCalledWith({
userPoolId,
clientId,
tokenUse: tokenType,
});
expect(mockVerifier.verify).toHaveBeenCalledWith(token);
});

it('should return false for an invalid token', async () => {
const mockVerifier: any = {
verify: jest.fn().mockRejectedValue(new Error('Invalid token')),
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Amazon Web Services",
"name": "@aws-amplify/adapter-nextjs",
"version": "1.2.3",
"version": "1.2.4",
"description": "The adapter for the supporting of using Amplify APIs in Next.js.",
"peerDependencies": {
"aws-amplify": "^6.0.7",
Expand Down
8 changes: 8 additions & 0 deletions packages/adapter-nextjs/src/utils/isValidCognitoToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { CognitoJwtVerifier } from 'aws-jwt-verify';
import { JwtExpiredError } from 'aws-jwt-verify/error';

/**
* Verifies a Cognito JWT token for its validity.
Expand Down Expand Up @@ -30,6 +31,13 @@ export const isValidCognitoToken = async (input: {

return true;
} catch (error) {
// When `JwtExpiredError` is thrown, the token should have valid signature
// but expired. So, we can consider it as a valid token.
// Reference https://github.com/awslabs/aws-jwt-verify/blob/8d8f714d7281913ecd660147f5c30311479601c1/src/jwt-rsa.ts#L290-L301
if (error instanceof JwtExpiredError) {
return true;
}

// TODO (ashwinkumar6): surface invalid cognito token error to customer
// TODO: clear invalid tokens from Storage
return false;
Expand Down

0 comments on commit d93b687

Please sign in to comment.