Making simple signup and login with mockoon

424 views Asked by At

One question, maybe it's a bit longer, but I really hope someone can help me. I've been reading the docs but simply can't figure it out.

Is there a way I can create a signup feature where user creates an account (only simple one, email and pw) , and that account data is saved somewhere in a JSON file

And then the user can login via post method by typing his credentials. And if credentials are correct (out of any other credentials there are in that particular JSON file) he gets a random jwt. I mean I know I need to set up the rules if email and pw match any user and pw from the JSON file

1

There are 1 answers

0
255kb - Mockoon On

[Update 2024-01-01] Since v6.1.0, Mockoon added support for global variables.

They allow you to generate and save data globally on a specific endpoint and reuse them anywhere.

The syntax is the following:

{{setGlobalVar 'myVar' 'myValue'}}
{{getGlobalVar 'myVar'}}

You can easily combine them with other helpers to retrieve and save data from the body, for example:

{{setGlobalVar 'login' (bodyRaw 'credentials.login')}}
{{setGlobalVar 'password' (bodyRaw 'credentials.password')}}

{{getGlobalVar 'login'}}
{{getGlobalVar 'password'}}

Full documentation.


Mockoon offers mostly stateless and independant endpoints mocking. Which means, there is currently no easy way to "code" it for such advanced use cases. You can simulate a POST /signup and POST /login call, make sure the request looks OK by using Mockoon's rules, but they will not be linked and the credentials will not be persisted. A system of CRUD endpoints is currently under development but it will allow for JSON manipulation only, not the kind of behavior you describe which is also very close to a production application.