# Token in appSession cookie cannot be decoded

**URL:** <https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591>\
**Category:** Get Help\
**Tags:** cookie, nextjs\
**Created:** [April 6, 2021, 5:16am UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591 "2021-04-06T05:16:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![williamwjs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/williamwjs/32/28599_2.png) [@williamwjs](https://community.auth0.com/u/williamwjs)\
**Post date:** [April 6, 2021, 5:16am UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591/1 "2021-04-06T05:16:37Z")

</div>

We are using nextjs auth0 SDK to integrate: [GitHub - auth0/nextjs-auth0: Next.js SDK for signing in with Auth0](https://github.com/auth0/nextjs-auth0)

However, the `appSession` cookie (with value eyJhbGciOiJka…) generated from it does seem to be in JWT format, which also looks to be much longer, and our backend could not decode it.

May I ask any idea why? And how should I decode the token?  
Thank you!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 7, 2021, 2:47pm UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591/3 "2021-04-07T14:47:38Z")

</div>

Hi @williamwjs,

The appSession cookie is an encrypted cookie. You can decode the token header, but that is the only info available:

```auto
{
  "alg": "dir",
  "enc": "A256GCM",
  "iat": 1617803479,
  "uat": 1617803480,
  "exp": 1617889880
}

```

Would you mind providing more context around your use case to see how I might help you get the info you need? Thanks!

---

<div class="post-metadata">

**Author:** ![williamwjs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/williamwjs/32/28599_2.png) [@williamwjs](https://community.auth0.com/u/williamwjs)\
**Post date:** [April 8, 2021, 2:55am UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591/4 "2021-04-08T02:55:28Z")

</div>

@stephanie.chamblee Thank you for your reply!

May I ask which header are you referring to?

Through the SDK, it callbacks with [http://localhost:3000/api/auth/callback?code=...&state=](http://localhost:3000/api/auth/callback?code=...&state=)…  
And I only saw `Set-Cookie` in the response header, which having the `appSession` that is un-decodable

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [April 8, 2021, 12:17pm UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591/5 "2021-04-08T12:17:00Z")

</div>

> [@williamwjs](#):
>
> May I ask which header are you referring to?

I was referring to the part of the token before the first period. For example, if you paste this token in [jwt.io/](http://jwt.io/), you’ll see the header decoded, but not the payload:

```auto
eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaWF0IjoxNjE3ODAzNDc5LCJ1YXQiOjE2MTc4ODE3MjUsImV4cCI6MTYxNzk2ODEyNX0..TIKxzG4pPsaR94xs.OcYKxDstl98CUxx9NfgjfBMNwjxChdT8CPP0ieAW6ODsBXBFaoPCIgBwGrZMxzDctd2nQs0eG52q1FGynbh4zmD1 __Wu5zLlUHBojHCZB-kuJPLP-kzMxggr9dpQ7oZL02MgUh689Kh3byV6513QG3JSWw7kOmlll7o87aGrEShDPIxvaprHlDfM2iCfq9GJU0UuqHIhRAqWulrhVjEqDWuD9hwUVPQYVVQMkyF1JuNlqjzgFC0bKN0y_QSCLUMF8_SgoRyRYwJDSyFt_KV0dTYSpkcsGfL2vOuV6C5FI4VQvi-TX58tL0S18tnyviiZ7Qf73LNagysiXNW23QOwG61HEgDqhHdcAIHQgmnvkbbzXj2EeeRjYyXLiRPATBEEHLAcxm3x3yKNMsdDcWYNdEyPGTDlyk1aOhgA514AxzJbJFXqrJVm8D_S8VU1uUa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EC01qqPGQ6xbMO-rJMDWXXSfCfrxJH3Vph-oekmR6IGqbCS0wJU-bspkR0UOxpri7lGbIiMYNsWpELlnxWFS2YjdFzW9vFJYwc9IYOGRPFEgSl_DYwZ652w9Ijy4wjv3EJxh_PIHQNvMxVCNFyUdZCZsIQUn3ZfC-GxMCfh4IxRYJUeH5-E0E7U659aquFH9QEbqiayVQpv1KoXURcp0NTmYLjlil2EhHuJTGEE9AZIB2ItORjpM9NeOWCrjPZQ3sOlDCRP76Z0D3H52_sVx2QC0CD0bL8KFOlMvknj5QlwzMUIFqGgqT65bSyGX0MOU1YCJI84d7f7ClxWe_3W-w4DNbkOHydBD5slercxAFdpSQ2yEmWRLNW_GMUMsKu_rKKLZKyuPgtzhRRaq71VHJFEABIW6sh839oqYzuurnQT2PdKveleUWDBroryWBA0jm3VUMmZAPxO3-RbSwqez48dN_ATO_pkQocsiFThcaQ1Q1LsJjy9oeSptfRcN7lLA4_0ed8k2VZgFSJdGpS9xwDnlFBm6UB2VU1dLToiR634nkOaqshDJ4qz8zYvebGq8jkRa5josifjBU4zeE20DQwf1fqRhRd5ZsODlyxZ6U8YTkwajG4lhKq5vrzjsLKJWGdN7SMifPTdGTerc1akh7cQrIVocLNR.LbtkXlpuQ9MxUWwDcyZJmQ

```

 ![Screen Shot 2021-04-08 at 7.39.22 AM](https://global.discourse-cdn.com/auth0/original/3X/2/7/276d0ae903a9ac207e76de052ddd5780610decdc.png)

The `appSession` cookie is used by the `nextjs-auth0` SDK, but there is no need to decrypt it in your own code.

In most app architectural models, the client would receive an ID Token (a JWT that contains the user info). However, the `nextjs-auth0` SDK will not expose the ID Token (or Access Token) to the client at all. If you were to check the network tab of dev tools in the browser, there’d be no way to find authentication info since this is all handled server-side.

In your app, to get user info from the ID Token, you’ll wrap the app in the `UserProvider` component, which will allow you to access user info in the client using the `useUser` hook. To use an Access Token to make a secure API request, you can use the SDK’s `getAccessToken` function.

This article explains how this works in the “Serverless with the user on the backend” section: [How to Authenticate with Next.js and Auth0: A Guide for Every Deployment Model](https://auth0.com/blog/ultimate-guide-nextjs-authentication-auth0/#Serverless-with-the-user-on-the-backend).

---

<div class="post-metadata">

**Author:** ![williamwjs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/williamwjs/32/28599_2.png) [@williamwjs](https://community.auth0.com/u/williamwjs)\
**Post date:** [April 8, 2021, 8:11pm UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591/6 "2021-04-08T20:11:44Z")

</div>

Ah I see.  
@stephanie.chamblee Thank you for the link! That is really helpful!!!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 23, 2021, 8:12pm UTC](https://community.auth0.com/t/token-in-appsession-cookie-cannot-be-decoded/60591/7 "2021-04-23T20:12:32Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
