-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback.html
More file actions
62 lines (56 loc) · 2.29 KB
/
callback.html
File metadata and controls
62 lines (56 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nylas Connect - Callback</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="flex items-center justify-center min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100">
<div class="text-center">
<div class="animate-spin rounded-full h-16 w-16 border-b-2 border-blue-600 mx-auto mb-4"></div>
<p class="text-gray-600">Completing authentication...</p>
</div>
</div>
<script type="module">
// Import Nylas Connect
import { NylasConnect } from 'https://esm.sh/@nylas/connect@latest';
// Initialize with the same configuration
const nylas = new NylasConnect({
clientId: '93dde230-d388-4404-98ed-6e10aacd3ea1',
redirectUri: window.location.origin + '/callback.html',
persistTokens: true,
apiUrl: 'https://api.us.nylas.com/v3',
});
// Handle the callback
(async () => {
try {
// Process the OAuth callback
await nylas.callback();
// If we're in a popup, close it and notify the opener
if (window.opener) {
window.opener.postMessage({ type: 'nylas-auth-success' }, window.location.origin);
window.close();
} else {
// If not a popup, redirect back to the main page
window.location.href = '/';
}
} catch (error) {
console.error('Callback error:', error);
// Notify opener of error if in popup
if (window.opener) {
window.opener.postMessage({
type: 'nylas-auth-error',
error: error.message
}, window.location.origin);
window.close();
} else {
// If not a popup, redirect back to the main page with error
window.location.href = '/?error=' + encodeURIComponent(error.message);
}
}
})();
</script>
</body>
</html>