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

Addition of login button which shows Hello, <username> , if user is logged in #64

Merged
merged 4 commits into from
Oct 14, 2020

Conversation

Rucha1499
Copy link
Contributor

@Rucha1499 Rucha1499 commented Oct 11, 2020

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
image

Copy link
Contributor

@swarajpure swarajpure left a 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) => {
Copy link
Contributor

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")
Copy link
Contributor

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))
Copy link
Contributor

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?

Copy link
Contributor Author

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!

swarajpure
swarajpure previously approved these changes Oct 13, 2020
Copy link
Contributor

@swarajpure swarajpure left a 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, {
Copy link
Contributor

@swarajpure swarajpure Oct 14, 2020

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.

Read more here: https://stackoverflow.com/questions/34807614/should-i-wait-for-domcontentloaded-event-if-i-place-a-script-tag-at-the-end-of-a#:~:text=If%20script%20modifies%20element%2C%20it,until%20it's%20sure%20it%20exists.

Copy link
Contributor Author

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!

Copy link
Contributor

@swarajpure swarajpure left a 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!

@swarajpure swarajpure merged commit 905168c into Real-Dev-Squad:main Oct 14, 2020
@Rucha1499 Rucha1499 changed the title Addition of login button on welcome site. Addition of login button which shows Hello, <username> , if user is logged in Jun 12, 2021
kush-x7 pushed a commit that referenced this pull request Nov 14, 2022
Updates README.md to include fix for CORS error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Login button to appear on Welcome site
3 participants