ios – react-native-apple-authentication decode with jwt-decode not working


Following react-native-apple-authentication I want to use jwt-decode on the identityToken returned by the apple login to catch informations like the email, following jwt-decode.
So by using import "core-js/stable/atob"; I realize I don’t have the core-js folder in my node_modules so I leave import "atob" which I have, so with the following code:

import { jwtDecode } from "jwt-decode";
import "atob"
const signInAppleAuth = async () => {
    const appleAuthRequestResponse = await appleAuth.performRequest({
        requestedOperation: appleAuth.Operation.LOGIN,
        requestedScopes: [appleAuth.Scope.FULL_NAME, appleAuth.Scope.EMAIL],
    });
    const { identityToken } = appleAuthRequestResponse
    const decoded = jwtDecode(identityToken)
    console.log(" decoded: ", decoded);
}

It gives me this:

InvalidTokenError: Invalid token specified: invalid json for part #2
(JSON Parse error: Unable to parse JSON string)

And when I use the token in jwt.io it works well. Why ?

Note:I also don’t have the base-64 folder in my modules for this solution :

import { decode } from "base-64";
global.atob = decode;

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img