Skip to content

Commit

Permalink
fix: login in mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Jun 18, 2022
1 parent ea1bb19 commit 76a7c65
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/browser/assets/callback.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@
<script>
var code = (/[?&]code=([^\s&]+)($|&)/.exec(location.search) || [])[1];
var state = (/[?&]state=([^\s&]+)($|&)/.exec(location.search) || [])[1];
window.opener.postMessage({ code: code, state: state }, location.origin);
window.close();
if (window.opener) {
window.opener.postMessage({ code: code, state: state }, location.origin);
window.close();
} else {
fetch(`https://ehtt.herokuapp.com/auth/${code}?state=${state}`)
.then((res) => res.json())
.catch((error) => ({ error }))
.then(({ token, error }) => {
if (token) {
localStorage.setItem('github_oauth_token', token);
}
window.close();
});
}
</script>
</head>
</html>

0 comments on commit 76a7c65

Please sign in to comment.