Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Created October 24, 2019 04:22
Show Gist options
  • Save PrimeTimeTran/566b8751a950fd1aeb786e15feac0fa3 to your computer and use it in GitHub Desktop.
Save PrimeTimeTran/566b8751a950fd1aeb786e15feac0fa3 to your computer and use it in GitHub Desktop.
useEffect(() => {
const existingToken = sessionStorage.getItem("token");
const accessToken =
window.location.search.split("=")[0] === "?access_token"
? window.location.search.split("=")[1]
: null;
if (!accessToken && !existingToken) {
window.location.replace(
`https://github.com/login/oauth/authorize?scope=user:email,repo&client_id=${clientId}`
);
}
if (accessToken) {
setToken(accessToken);
sessionStorage.setItem("token", accessToken);
}
if (existingToken) {
setToken(existingToken);
}
getIssues();
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment