{"version":3,"file":"isValidCognitoToken.mjs","sources":["../../../src/utils/isValidCognitoToken.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { JwtExpiredError } from 'aws-jwt-verify/error';\n/**\n * Verifies a Cognito JWT token for its validity.\n *\n * @param input - An object containing:\n *                - token: The JWT token as a string that needs to be verified.\n *                - verifier: The JWT verifier which will verify the token.\n * @internal\n */\nexport const isValidCognitoToken = async (input) => {\n    const { token, verifier } = input;\n    try {\n        await verifier.verify(token);\n        return true;\n    }\n    catch (error) {\n        // When `JwtExpiredError` is thrown, the token should have valid signature\n        // but expired. So, we can consider it as a valid token.\n        // Reference https://github.com/awslabs/aws-jwt-verify/blob/8d8f714d7281913ecd660147f5c30311479601c1/src/jwt-rsa.ts#L290-L301\n        if (error instanceof JwtExpiredError) {\n            return true;\n        }\n        // TODO (ashwinkumar6): surface invalid cognito token error to customer\n        // TODO: clear invalid tokens from Storage\n        return false;\n    }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,mBAAmB,GAAG,OAAO,KAAK,KAAK;AACpD,IAAI,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK;AACrC,IAAI,IAAI;AACR,QAAQ,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC;AACpC,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,KAAK,EAAE;AAClB;AACA;AACA;AACA,QAAQ,IAAI,KAAK,YAAY,eAAe,EAAE;AAC9C,YAAY,OAAO,IAAI;AACvB,QAAQ;AACR;AACA;AACA,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ;;;;"}