-
Notifications
You must be signed in to change notification settings - Fork 93
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
Feat: Issue#30 protected page and Persistent Token #34
Feat: Issue#30 protected page and Persistent Token #34
Conversation
Updatte @anitab-org/bridgeintech-maintainers . I've just pushed the latest code. Please give your feedback. In the meantime I'll start backend GET /user profile. |
src/login/Login.jsx
Outdated
fetch("http://127.0.0.1:5000/login", requestLogin) | ||
.then(async response => { | ||
let data = await response.json(); | ||
if (response.status === 200) { | ||
if (data !== {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is your purpose to see if data is an empty object?
Please look into considerations for such tests, and I would recommend using one of the suggestions from here: https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another resource: https://stackoverflow.com/questions/4994201/is-object-empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ramitsawhney27 . I've changed it to one of the suggested option (using underscore library _.isEmpty(obj)) 👍
src/login/Login.jsx
Outdated
@@ -25,21 +25,26 @@ export default function Login() { | |||
}, | |||
body: JSON.stringify(payload) | |||
}; | |||
|
|||
fetch("http://127.0.0.1:5000/login", requestLogin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a constant, like LOCALHOST="http://...."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Changed it to BASE_API_URL
Update @anitab-org/bridgeintech-maintainers and @ramitsawhney27 . I have made the changes as per @ramitsawhney27 suggestion. Please let me know if you have any other feedback 😉. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me, great work on the quick turnaround @mtreacy002!
Just wanna share latest codesandbox incase anyone wanna try it out. Note: for some reason the app doesn't work the same on sandbox and VSCode. not sure why. To test the final code change, try to test directly from PR branch. |
Update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've fixed the bugs. Now this PR is complete. Logout option on Navbar now automatically shown after successful login. |
src/Routes.js
Outdated
); | ||
export const SessionUser = createContext(Cookies.get("user")); | ||
export const BASE_API_URL = "http://127.0.0.1:5000"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could abstract all this Context to a separate component
I finally found a good example:
https://codesandbox.io/s/p71pr7jn50?file=/src/AuthContext.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can explain more on this in our catch up today.
Maya this is some great work! Especially because I know you had to research about everything and I haven't been of much help lately. Great work! We can pair and work on the changes together during our catchup. |
…NavLink href as to
Protected page fix
Update @meenakshi-dhanani . I've merged your changes into this PR branch. Thanks for the fix. It looks great 😉. |
There is an unnecessary component for Logout, it could be done within a method and history.push instead of Redirect. It's fine though if we tackle that improvement in a separate PR. Since I understand this PR has been open for long. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anitab-org/bridgeintech-maintainers can you review this PR? |
@foongminwong can you review this PR? |
Yes I'll review this by today |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes made in this PR were tested locally. Following are the results:
-
Code review - Done by @meenakshi-dhanani and @ramitsawhney27
-
All possible responses were tested as below:
-
Additional testcases covered: N/A
-
OS Version: Windows 10
Description
Add ProtectedPage functionality to separate Public vs Private/Members-only pages
Fixes #30
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
Updated gif link
Checklist:
Code/Quality Assurance Only