-
Notifications
You must be signed in to change notification settings - Fork 98
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
Addition of login button which shows Hello, <username>
, if user is logged in
#64
Conversation
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.
Minor changes required. Thanks!
js/login.js
Outdated
@@ -0,0 +1,16 @@ | |||
const userLogin = document.querySelector("#login-btn") | |||
|
|||
const setUserName = (name) => { |
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.
Arrow functions are not supported in IE and Opera Mini.
Preferable to use ES5 syntax here.
js/login.js
Outdated
@@ -0,0 +1,16 @@ | |||
const userLogin = document.querySelector("#login-btn") |
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.
Can we have this declaration inside the function itself? It's not being used anywhere else.
js/login.js
Outdated
"credentials": "include" | ||
}) | ||
.then(res => res.json()) | ||
.then(res => setUserName(res.first_name)) |
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.
Can the function name be a bit more descriptive? Like setNameIfFound
?
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 with the changes as per review. Thanks!
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.
Looks good to me. Thank you!
Adding the login button to the rest of the pages can be a good beginner-friendly issue.
js/login.js
Outdated
|
||
let url = "https://staging-api.realdevsquad.com/users/self" | ||
let url = "https://staging-api.realdevsquad.com/users/self"; | ||
|
||
fetch(url, { |
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.
What if we could call the fetch after the DOM Content is loaded?
We can directly shift this code inside the eventListener of DOMContentLoaded but it wouldn't be much readable. For that we could wrap the fetch call in a function and pass that function to the eventListener.
Why am I saying so is that if someone moves the <script>
tag in the <head>
, since the JS has referred the some DOM content, it won't find it and fail.
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 with the changes. Thanks for the review!
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.
Looks good to me. Thank you!
Hello, <username>
, if user is logged in
Updates README.md to include fix for CORS error
Added the login button on welcome site. It displays " Hello username! ", if the user is logged in. The "username" is the first name of user. Fixes #60