HackYourFuture-CPH / web-dev-rooms

Final project for HYF class14
https://develop-web-dev-rooms.herokuapp.com
MIT License
0 stars 4 forks source link

INFO - How to authenticate users #255

Closed tpetrina closed 3 years ago

tpetrina commented 3 years ago

To test via Postman or any other REST tool, ensure that the request has a header Authorization set to Bearer TOKEN:{SLACKDI} where SLACKID is the slackId from the database. Check the seeds.

This will ensure that the user is the one found in the database.

image

From the frontend side, look at the example in StudentRegistrationPage:

Post, put and patch look like this:

        const { fetch } = useAuthenticatedFetch();

        await fetch(`/api/user/register/student`, {
        method: 'post',
        data: {
          name,
          groupId,
        },
      });

If you need to GET:

const { fetch } = useAuthenticatedFetch();

await fetch(`/api/user/register/student`);

For delete:

const { fetch } = useAuthenticatedFetch();
await fetch(`/api/user/register/student`, {
  method: 'delete'
});
tpetrina commented 3 years ago

Moved to https://github.com/HackYourFuture-CPH/web-dev-rooms/blob/develop/Authentication.md.