Next.js Discord

Discord Forum

DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encode

Unanswered
Hassib posted this in #help-forum
Open in Discord
Hi, I'm trying to decode a string which is returned from an API endpoint using the atob function of JavaScript in my Next.js project. Everything works find on localhost but when deployed on Vercel, it throws the error.

Note: I validated the string before parsing and decoding, it has no errors.

Here's the code:

  const { mutate: mutateAdminLogin, isLoading } = useAdminLoginMutation({
    onSuccess(result) {
      const { token, resource, user } = result;
      setToken(token);
      setResources(JSON.parse(atob(resource)));
      setUser({
        id: user?.id,
        name: user?.name,
      });
      supportStore.setId(user?.support?.id);
      supportStore.setDept(user?.support?.dept);
      supportStore.setStatus(user?.support?.status);
      router.push(DASHBOARD_PAGE);
    },
    onError(error: AxiosError) {
      queryClient.invalidateQueries(CAPTCHA_QUERY_KEY);
      manageErrors(error, [
        {
          code: API_ERRORS.login_failed,
          message: 'Login Failed: Invalid credentials',
        },
      ]);
    },
  });

1 Reply

Hi again 👋