awslabs / aws-jwt-verify

JS library for verifying JWTs signed by Amazon Cognito, and any OIDC-compatible IDP that signs JWTs with RS256, RS384, and RS512
Apache License 2.0
598 stars 43 forks source link

[QUESTION] Module parse failed: Unexpected token (260:61) #84

Closed romankurnovskii closed 1 year ago

romankurnovskii commented 1 year ago

Question Facing an issue using react

Versions

./node_modules/aws-jwt-verify/dist/esm/cognito-verifier.js 260:61
Module parse failed: Unexpected token (260:61)
You may need an appropriate loader to handle this file type.
|     key: "create",
|     value: function create(verifyProperties, additionalProperties) {
>       return new this(verifyProperties, additionalProperties?.jwksCache);
|     }
|   }]);
ottokruse commented 1 year ago

Hi @romankurnovskii I can't reproduce this.

I did:

Might be a versions thing. Perhaps clear your npx cache and run create-react-app again?

// App.js
import logo from "./logo.svg";
import "./App.css";
import { CognitoJwtVerifier } from "aws-jwt-verify"; // added

// added:
const verifier = CognitoJwtVerifier.create({
  userPoolId: "<user pool id>",
  clientId: "<client id>",
  tokenUse: "access"
});

function App() {
  console.log(verifier); // added, just a dummy usage
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;
ottokruse commented 1 year ago

Closing for now, let us know if the issue persists.

jack-sparroow commented 1 year ago

I'm facing the same issue while decoding the jwt-id-token on FE.

I have solved it (temporarily) using this.

    JSON.parse(atob(token.split(".")[1]))