+10
src/components/pages/grain-oauth-callback.js
+10
src/components/pages/grain-oauth-callback.js
···
1
import { LitElement, html, css } from 'lit';
2
+
import { auth } from '../../services/auth.js';
3
import '../atoms/grain-spinner.js';
4
5
export class GrainOAuthCallback extends LitElement {
···
17
font-size: var(--font-size-sm);
18
}
19
`;
20
+
21
+
async connectedCallback() {
22
+
super.connectedCallback();
23
+
const params = new URLSearchParams(window.location.search);
24
+
if (params.get('start') === '1') {
25
+
window.history.replaceState({}, '', '/oauth/callback');
26
+
await auth.startOAuthFromCallback();
27
+
}
28
+
}
29
30
render() {
31
return html`
+12
-4
src/services/auth.js
+12
-4
src/services/auth.js
···
60
61
async login(handle) {
62
sessionStorage.setItem('oauth_return_url', window.location.pathname);
63
+
sessionStorage.setItem('oauth_handle', handle);
64
+
window.location.href = '/oauth/callback?start=1';
65
+
}
66
+
67
+
async startOAuthFromCallback() {
68
+
const handle = sessionStorage.getItem('oauth_handle');
69
+
sessionStorage.removeItem('oauth_handle');
70
+
if (!handle) {
71
+
router.replace('/');
72
+
return;
73
+
}
74
+
await this.#client.loginWithRedirect({ handle });
75
}
76
77
logout() {