SuperTokens core threw an error for a POST request to path: /recipe/signup with status code: 500 and message: Internal Error

This error can be caused by attempting to create and manage user accounts while using MongoDB as the database for SuperTokens. Unfortunately, SuperTokens can only use MongoDB as the backend database for session management. To fix this error, you’ll have to use a different database like MySQL.

I discovered this error while working on the full-stack SuperTokens example. If you’re new to using SuperTokens and want to see an example to get started quickly, you should check it out.

Problem: you are using MongoDB for SuperTokens but need user account management

If you’re already using MongoDB as the database for your app, it can be tempting to just use it for SuperTokens as well like this:

       - PROD=${PROD}
   mongodb:
     image: mongo
   supertokens:
     image: supertokens/supertokens-mongodb
     environment:
       - MONGODB_CONNECTION_URI="mongodb://mongodb/supertokens"
YAML

If you attempt to create a user, however, you’ll have the following error on the frontend:

And you’ll have a nasty looking stack trace on the backend:

[...]    
 return await self.__send_request_helper(path, "POST", f, len(self.__hosts))
   File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 246, in __send_request_helper
     raise_general_exception(e)
   File "/usr/local/lib/python3.9/site-packages/supertokens_python/exceptions.py", line 23, in raise_general_exception
     raise msg
   File "/usr/local/lib/python3.9/site-packages/supertokens_python/querier.py", line 225, in __send_request_helper
     raise_general_exception(
   File "/usr/local/lib/python3.9/site-packages/supertokens_python/exceptions.py", line 26, in raise_general_exception
     raise GeneralError(msg) from previous
 supertokens_python.exceptions.GeneralError: SuperTokens core threw an error for a POST request to path: /recipe/signup with status code: 500 and message: Internal Error

It’s not immediately apparent in the SuperTokens documentation, but the MongoDB SuperTokens image does not support user management, only session management. The stack trace isn’t much help when trying to figure this out, either.

Solution: use another database like MySQL

To fix this, we have to use a different database for our SuperTokens image. For our full stack SuperTokens example, we went with MySQL:

    - PROD=${PROD}
mysql:
  image: mysql
  environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_USER: supertokens
        MYSQL_PASSWORD: supertokens
        MYSQL_DATABASE: supertokens
supertokens:
  image: supertokens/supertokens-mysql
  environment:
    - MYSQL_CONNECTION_URI="mysql://supertokens:supertokens@mysql/supertokens"
YAML

This does unfortunately mean you’re going to need yet another container in your stack (if you were using MongoDB already for app data), but it’s good practice to keep your user account and authentication information separate anyway.

Conclusion

The SuperTokens MongoDB image only supports session management. This means if you need user accounts in your app, you’ll have to use another database for SuperTokens, such as MySQL.