1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-10-01 19:36:43 +02:00

feat: user accounts functionality (#3813)

* feat: integrate astro

* chore: login popup design

* chore: data-popup changed

* refactor: github and google button

* chore: signup page

* chore: login popup design

* chore: signup page design

* chore: auth divider

* feat: integrate astro

* chore: login popup design

* chore: data-popup changed

* refactor: github and google button

* chore: signup page

* chore: login popup design

* chore: signup page design

* chore: auth divider

* chore: login feature

* chore: login error message

* chore: added name in token decode return

* chore: use auth hook

* chore: logout vs login

* chore: download button link

* chore: account dropdown

* fix: dropdown z index

* chore: profile page

* Add missing content for backend roadmap

* Remove unused styles

* Add login with google

* chore: google login implementation

* chore: profile guard clause

* fix: button size

* chore: preact to astro components

* chore: preact to astro comp

* chore: github astro component

* chore: google login error handling

* chore: github login error handling

* chore: change password page

* chore: rename profile to password

* fix: change password rename

* chore: update profile page

* chore: setting sidebar

* fix: setting dropdown design

* chore: required indicator

* chore: change password form

* chore: update profile form

* chore: mobile navigation

* fix: form data empty error

* chore: email login and signup components

* chore: forgot password page

* chore: reset password page

* chore: verify account page

* chore: resend verification email

* fix: types in spinner

* chore: forgot password functionality

* fix: class -> className

* chore: reset password page

* chore: reset password functionality

* chore: login page

* fix: spacing for login and signup page

* refactor: email login form

* chore: astro spinner

* chore: pre-fill user data

* chore: dummy placeholder

* chore: forgot password link add

* fix: replaced constants

* chore: forgot password link

* chore: change password for social provider

* chore: internal pages guard

* chore: internal paths

* refactor: change password errors

* refactor: update profile errors

* chore: mark as done overlay

* fix: uncontrolled to controlled form

* fix: de-structure error

* chore: error messages

* fix: 401 error code redirect to login page

* chore: loading spinner accessibilities

* fix: remove spinner

* chore: keep spinner after success to redirect

* chore: keep the spinner

* style: resend email underline

* chore: chevron down account

* chore: roadmap pdf link download

* chore: roadmap pdf link download

* chore: best practices buttons

* fix: verify account text

* fix: topic overlay hide

* chore: base verify design

* chore: email verify page

* fix: div tag missing

* Formatting

* Refactor top navigation

* Prettier

* Update dependencies

* Refactor top navigation

* Refactor login button

* Remove captcha and add google scripts

* Refactor email sign up form

* Resend verfication email functionality

* Refactor verification pending page

* Add verify account functionality

* Update signup text

* Add login page

* Add login button in top nav

* Email login form

* Handle authenticatoin

* Show hide auth elements change

* Add ease-in on the guest elements

* Refactor logic for download and subscribe popups

* Add forgot password

* Rename fetch lib

* Add authentication popup

* Refactor logic for mark done and pending

* Handle logout

* Add route protection

* Popup opener to close the overlay

* Remember page when logging in

* Add reset password page

* Change placement of constant

* Update profile page

* Add update password form

* Update password page

* Update profile page

* Update design

* chore: toggle mark resource done api

* chore: toggle topic done

* chore: get user resource progress api

* fix: best practice topic toggle

* chore: fetch progress

* fix: query selector for topics

* Keep track of the old page before social login

* Update public api url

* Add user progress tracking

* Update topic done functionality

* Add progress loader

* Add page wide spinner

* Add spinner on setting pages

* Add fingerprint to user requests

* Use http wrapper instead of fetch

* Update fingerprint

* Minor improvements

---------

Co-authored-by: Arik Chakma <arikchangma@gmail.com>
This commit is contained in:
Kamran Ahmed
2023-04-14 19:22:52 +01:00
committed by GitHub
parent c5645299aa
commit a2719bc771
82 changed files with 3744 additions and 1191 deletions

View File

@@ -0,0 +1,116 @@
import { useEffect, useState } from 'preact/hooks';
import GitHubIcon from '../../icons/github.svg';
import SpinnerIcon from '../../icons/spinner.svg';
import Cookies from 'js-cookie';
import { TOKEN_COOKIE_NAME } from '../../lib/jwt';
import { httpGet } from '../../lib/http';
type GitHubButtonProps = {};
const GITHUB_REDIRECT_AT = 'githubRedirectAt';
const GITHUB_LAST_PAGE = 'githubLastPage';
export function GitHubButton(props: GitHubButtonProps) {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState('');
const icon = isLoading ? SpinnerIcon : GitHubIcon;
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const state = urlParams.get('state');
const provider = urlParams.get('provider');
if (!code || !state || provider !== 'github') {
return;
}
setIsLoading(true);
httpGet<{ token: string }>(
`${import.meta.env.PUBLIC_API_URL}/v1-github-callback${
window.location.search
}`
)
.then(({ response, error }) => {
if (!response?.token) {
const errMessage = error?.message || 'Something went wrong.';
setError(errMessage);
setIsLoading(false);
return;
}
let redirectUrl = '/';
const gitHubRedirectAt = localStorage.getItem(GITHUB_REDIRECT_AT);
const lastPageBeforeGithub = localStorage.getItem(GITHUB_LAST_PAGE);
// If the social redirect is there and less than 30 seconds old
// redirect to the page that user was on before they clicked the github login button
if (gitHubRedirectAt && lastPageBeforeGithub) {
const socialRedirectAtTime = parseInt(gitHubRedirectAt, 10);
const now = Date.now();
const timeSinceRedirect = now - socialRedirectAtTime;
if (timeSinceRedirect < 30 * 1000) {
redirectUrl = lastPageBeforeGithub;
}
}
localStorage.removeItem(GITHUB_REDIRECT_AT);
localStorage.removeItem(GITHUB_LAST_PAGE);
Cookies.set(TOKEN_COOKIE_NAME, response.token);
window.location.href = redirectUrl;
})
.catch((err) => {
setError('Something went wrong. Please try again later.');
setIsLoading(false);
});
}, []);
const handleClick = async () => {
setIsLoading(true);
const { response, error } = await httpGet<{ loginUrl: string }>(
`${import.meta.env.PUBLIC_API_URL}/v1-github-login`
);
if (error || !response?.loginUrl) {
setError(
error?.message || 'Something went wrong. Please try again later.'
);
setIsLoading(false);
return;
}
// For non authentication pages, we want to redirect back to the page
// the user was on before they clicked the social login button
if (!['/login', '/signup'].includes(window.location.pathname)) {
localStorage.setItem(GITHUB_REDIRECT_AT, Date.now().toString());
localStorage.setItem(GITHUB_LAST_PAGE, window.location.pathname);
}
window.location.href = response.loginUrl;
};
return (
<>
<button
class="inline-flex h-10 w-full items-center justify-center gap-2 rounded border border-slate-300 bg-white p-2 text-sm font-medium text-black outline-none focus:ring-2 focus:ring-[#333] focus:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-60"
disabled={isLoading}
onClick={handleClick}
>
<img
src={icon}
alt="GitHub"
class={`h-[18px] w-[18px] ${isLoading ? 'animate-spin' : ''}`}
/>
Continue with GitHub
</button>
{error && (
<p className="mb-2 mt-1 text-sm font-medium text-red-600">{error}</p>
)}
</>
);
}