Bug: atob invalid character exception
See original GitHub issue- Review the documentation: https://docs.clerk.dev/
- Search for existing issues: https://github.com/clerkinc/javascript/issues
- Go through package changelog files.
- Provide the Frontend API key from your application dashboard.
Package + Version
-
@clerk/clerk-js
-
@clerk/clerk-react
-
@clerk/nextjs
-
@clerk/remix
-
@clerk/types
-
@clerk/themes
-
@clerk/clerk-expo
-
@clerk/backend-core
-
@clerk/clerk-sdk-node
-
@clerk/edge
- other:
Version:
4.5.2 also tested on latest 4.6.5
Browser/OS
If applicable e.g. Chrome latest
Description
When using a custom session claims with profile_image
the Clerk getAuth
function breaking on invalid character using atob
function. Getting the session token and unwrapping the image url is set to "profile_image": "https://www.gravatar.com/avatar?d=mp"
and we think the =
is probably breaking it. Here is the stack trace
Here is our custom claims object
{
"email": "{{user.primary_email_address}}",
"user_id": "{{user.id}}",
"last_name": "{{user.last_name}}",
"first_name": "{{user.first_name}}",
"email_verfied": "{{user.email_verified}}"
}
Stack trace error on login
error - DOMException [InvalidCharacterError]: Invalid character
at atob (node:buffer:1247:13)
at parseRequest (/Users/arashsoheili/Code/caredge-app/node_modules/@clerk/nextjs/dist/server/utils/getAuth.js:49:38)
at /Users/arashsoheili/Code/caredge-app/node_modules/@clerk/nextjs/dist/server/utils/getAuth.js:24:61
at eval (webpack-internal:///(api)/./src/api/common/handler/method.ts:67:83)
at resolver (webpack-internal:///(api)/./src/api/common/handler/index.ts:109:19)
at Object.apiResolver (/Users/arashsoheili/Code/caredge-app/node_modules/next/server/api-utils/node.ts:522:11)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async DevServer.runApi (/Users/arashsoheili/Code/caredge-app/node_modules/next/server/next-server.ts:789:5) {
page: '/api/auth/vehicles-owned'
}
Have tested removing the profile_image from custom session and we then have no issues.
The atob
function is deprecate. Here is the docs from nodejs
This function is only provided for compatibility with legacy web platform APIs and should never be used in new code, because they use strings to represent binary data and predate the introduction of typed arrays in JavaScript. For code running using Node.js APIs, converting between base64-encoded strings and binary data should be performed using Buffer.from(str, 'base64') and buf.toString('base64').
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
javascript atob returning 'String contains an invalid character'
I have an AJAX call getting info out of the Github API. It is returned in base64 encoding but when i try to...
Read more >Fix DOM Exception 5 invalid character with atob - dracoblue.net
When I was developing on http://web.twtxt.org I ran into this mysterious javascript error:InvalidCharacterError: DOM Exception 5: An invalid ...
Read more >Implementing Unicode support for btoa() and atob() | Examples
Thus, trying to encode a multibyte character to Base64, the btoa function will throw exception “Character Out Of Range” or “Invalid Character Error”....
Read more >javascript atob() detects invalid Base64 encoding and throws ...
The problem seems to be in trailing "=" character, because when this character is omitted, string is decoded by atob() successfully. But other...
Read more >atob should ignore spaces #42530 - nodejs/node - GitHub
No response What is the expected behavior? atob(' ') === '' What ... atob(' ') // => DOMException [InvalidCharacterError]: Invalid character ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. The fix will be live by the end of this week via https://github.com/clerkinc/javascript/pull/610.