Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user session #3

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

user session #3

wants to merge 11 commits into from

Conversation

aquino-luane
Copy link

What is this PR about

Consumes user information like username from mock api and stores result in redux store. The new username is shown in the top right menu:
image

How to setup the mock API

We are using Mockoon for API mock
Here is the file you need to set the mock API:

Link to drive: https://drive.google.com/drive/folders/1ASWqP-JZXjmFqD_akaFnZ5IdqY4hKGRQ

To import the route to Mockoon, you copy the contents of the json file, then in Mockoon you select from the menu Routes>Add routes from clipboard
https://mockoon.com/docs/latest/mockoon-data-files/environment-clipboard-copy/#create-a-new-route-from-clipboards-data

@aquino-luane aquino-luane mentioned this pull request Oct 9, 2024
@aquino-luane aquino-luane requested a review from hissy October 9, 2024 06:12
@aquino-luane aquino-luane self-assigned this Oct 9, 2024
Copy link
Member

@hissy hissy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. This PR helps me think about how we can treat user sessions.
Let's choose JWT to get the user name.

I've updated scratch-api.json and added token endpoint.

https://drive.google.com/file/d/1MXE6VUL1b22RWAef1OG6t3UwbIchOA62/view?usp=drive_link

It returns a token. You can decode it by using jwt-decode library.
https://www.npmjs.com/package/jwt-decode

Please store token itself also. We'll use it for every other API routes to authenticate.

@aquino-luane aquino-luane requested a review from hissy October 18, 2024 07:08
Copy link
Member

@hissy hissy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aquino-luane Thank you, it looks fine to me. What happens if the API doesn't return a token? If there's no valid user session, the API will return a 401 response.

Screenshot 2024-10-18 at 17 52 11

@aquino-luane
Copy link
Author

aquino-luane commented Oct 21, 2024

@aquino-luane Thank you, it looks fine to me. What happens if the API doesn't return a token? If there's no valid user session, the API will return a 401 response.

Screenshot 2024-10-18 at 17 52 11

Hi @hissy I will check what happens now, but do you already know what is the expected behavior? should I retry or just make another request to the token API to get a new token?

Are there other cases when there will be interaction with token API? I can see these two:

  1. login
    After the user enter username and password, and if is everything ok, then shows the Scratch app. The frontend make request to token API and keep it in store to use in other requests like autosave.

The only error I can see is server error like 500. In this case I think we should discuss the design part of what to show to user

  1. Autosave
    User make changes to project then the frontend makes an API request to the autosave API with project files and token in the payload. 
If token is invalid, then we make another request to get a new token. Then we try again the request to autosave API.

But if token is not returned then I think we also should discuss what to show to user. Maybe show a message in the menu bar:
image

@hissy
Copy link
Member

hissy commented Oct 21, 2024

@aquino-luane

Currently, we're working on POC. I just want to know if you can show an error when the API can't return the token now.

I asked @biplobice to create a document detailing the backend APIs. After he completes it, we'll be able to discuss more specific cases.
https://www.notion.so/Write-Design-Doc-for-Concrete-Package-125e6be67ce580209ca5c31fd3b96b59?pvs=4

@aquino-luane
Copy link
Author

@hissy I committed code changes to show an error (see image below) when token is not returned, could you check please?

image

src/containers/gui.jsx Show resolved Hide resolved
src/containers/gui.jsx Outdated Show resolved Hide resolved
@aquino-luane aquino-luane changed the title POC: user session user session Dec 27, 2024
@aquino-luane
Copy link
Author

I will add code to do the refresh part, so I will be editing this PR. Will request your code review again when it is done 🙇‍♀️
@hissy @biplobice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants