forked from nlweb-ai/NLWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_oauth_display.html
More file actions
157 lines (142 loc) · 5.51 KB
/
test_oauth_display.html
File metadata and controls
157 lines (142 loc) · 5.51 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html>
<head>
<title>Test OAuth Display</title>
<link rel="stylesheet" href="/static/common-chat-styles.css">
<link rel="stylesheet" href="/static/chat-page-styles.css">
<style>
body {
padding: 20px;
background: #f5f5f5;
}
.test-container {
max-width: 600px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.test-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
.test-button {
padding: 8px 16px;
background: #5e5eff;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
margin: 5px;
}
.test-button:hover {
background: #4d4dff;
}
.test-result {
margin-top: 20px;
padding: 15px;
background: #f9f9f9;
border-radius: 6px;
font-family: monospace;
font-size: 12px;
white-space: pre-wrap;
}
</style>
</head>
<body>
<div class="test-container">
<h1>OAuth Display Test</h1>
<div class="test-header">
<div>
<button class="login-button" id="loginBtn">Login</button>
<div class="user-info" id="userInfo" style="display: none;">
<span class="provider-icon" id="providerIcon"></span>
<span class="user-name" id="userName"></span>
<button class="logout-button" id="logoutBtn">Logout</button>
</div>
</div>
</div>
<div>
<h3>Test Different Provider Icons:</h3>
<button class="test-button" onclick="testProvider('google', 'Test User', 'test@gmail.com')">Test Google</button>
<button class="test-button" onclick="testProvider('github', 'GitHub User', 'github@test.com')">Test GitHub</button>
<button class="test-button" onclick="testProvider('facebook', 'FB User', 'fb@test.com')">Test Facebook</button>
<button class="test-button" onclick="testProvider('microsoft', 'MS User', 'ms@test.com')">Test Microsoft</button>
<button class="test-button" onclick="clearAuth()">Clear Auth</button>
</div>
<div>
<h3>Current Auth State:</h3>
<div class="test-result" id="authState"></div>
</div>
</div>
<script>
function updateAuthState() {
const authToken = localStorage.getItem('authToken');
const userInfo = localStorage.getItem('userInfo');
const stateDiv = document.getElementById('authState');
stateDiv.textContent = `AuthToken: ${authToken ? 'Present' : 'None'}\n`;
if (userInfo) {
try {
const parsed = JSON.parse(userInfo);
stateDiv.textContent += `UserInfo: ${JSON.stringify(parsed, null, 2)}`;
} catch (e) {
stateDiv.textContent += `UserInfo: Invalid JSON`;
}
} else {
stateDiv.textContent += `UserInfo: None`;
}
}
function testProvider(provider, name, email) {
const userInfo = {
id: '12345',
name: name,
email: email,
provider: provider
};
localStorage.setItem('authToken', 'test_token_' + provider);
localStorage.setItem('userInfo', JSON.stringify(userInfo));
updateUI(userInfo);
updateAuthState();
}
function updateUI(userInfo) {
const loginBtn = document.getElementById('loginBtn');
const userInfoDiv = document.getElementById('userInfo');
const userName = document.getElementById('userName');
const providerIcon = document.getElementById('providerIcon');
loginBtn.style.display = 'none';
userInfoDiv.style.display = 'flex';
userName.textContent = userInfo.name || userInfo.email || 'User';
// Set provider icon
if (providerIcon && userInfo.provider) {
providerIcon.className = `provider-icon ${userInfo.provider}`;
console.log('Set provider icon class to:', providerIcon.className);
}
}
function clearAuth() {
localStorage.removeItem('authToken');
localStorage.removeItem('userInfo');
document.getElementById('loginBtn').style.display = 'block';
document.getElementById('userInfo').style.display = 'none';
updateAuthState();
}
// Check existing auth on load
window.onload = function() {
const userInfoStr = localStorage.getItem('userInfo');
if (userInfoStr) {
try {
const userInfo = JSON.parse(userInfoStr);
updateUI(userInfo);
} catch (e) {
console.error('Failed to parse userInfo:', e);
}
}
updateAuthState();
};
</script>
</body>
</html>