globe-and-citizen / cnc-portal

The Crypto Native Portal, an app that creates a mechanism to financially acknowledge the micro contributions of Open Source collaborators along with tools that promote effective governance.
3 stars 0 forks source link

[Refactor] Refactoring Auth #263

Closed hermannleboss closed 3 weeks ago

hermannleboss commented 1 month ago

Description

Close #261

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

Get the user nonce: /api/user/nonce/{address} Sign and return to /api/auth/siwe And SIWE should return a token Use the token to authenticate the user /api/user/{address} And you get the user informations Then redirection to home page

{
  "user": null,
  "userIsAuth": false,
  "authToken": null
}

When the user is authenticated Then the value the user should be

{
  "user": {
    "address": "0x...",
     //...
  },
  "userIsAuth": true,
  "authToken": "[token]"
}

When the user is authenticated and go to the login page Then the user should be redirected to the home page

When the user is not authenticated and go to another page than the login page Then the user should be redirected to the login page

When the user is authenticated and have and 401 error Then the user should be logout then redirected to the login page

When the logout app is called Then the value the user should be set to

{
  "user": null,
  "userIsAuth": false,
  "authToken": null
}

When the user sign in Then the value of the user should be set to

  {
    "user": {
      "address": "0x...",
        //...
    },
    "userIsAuth": true,
    "authToken": "[token]"
  }

How to know if the user is authenticated

When the auth token is not null or the fetch do not return a 401 error. Then the app consider the user as authenticated

When the auth token is null or the fetch return a 401 error. Then the app consider the user as not authenticated And the user should be logedout

Acceptance Criteria