Skip to content

Commit 95b5522

Browse files
committed
Align landing page login experience.
1 parent e432900 commit 95b5522

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

default-templates/server/index.html

+37-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
<div class="container">
1212
<div class="page-header">
1313
<div class="pull-right">
14-
<a href="/register" class="btn btn-primary">
15-
Register
16-
</a>
14+
<a href="/register" class="btn btn-primary">Register</a>
1715

18-
<a href="/login" class="btn btn-success">
19-
Login
20-
</a>
16+
<a onclick="login()" class="btn btn-success">Login</a>
2117
</div>
2218

2319
<h1>Welcome to the Solid Prototype</h1>
@@ -30,6 +26,41 @@ <h1>Welcome to the Solid Prototype</h1>
3026

3127
If you have not already done so, please create an account.
3228
</p>
29+
30+
<p class="lead hidden" id="loggedIn">
31+
You are logged in as
32+
<a href="#" id="profileLink"></a>.
33+
</p>
3334
</div>
35+
<script src="/common/js/solid-auth-client.bundle.js"></script>
36+
<script>
37+
const elements = {};
38+
['loggedIn', 'profileLink'].forEach(id => {
39+
elements[id] = document.getElementById(id)
40+
})
41+
42+
async function login () {
43+
const session = await solid.auth.popupLogin()
44+
if (session) {
45+
// Make authenticated request to the server to establish a session cookie
46+
const {status} = await solid.auth.fetch(location)
47+
if (status === 401) {
48+
alert(`Invalid login.`)
49+
await solid.auth.logout()
50+
}
51+
}
52+
}
53+
54+
solid.auth.trackSession(async session => {
55+
if (!session) {
56+
elements.loggedIn.classList.add('hidden')
57+
}
58+
else {
59+
elements.loggedIn.classList.remove('hidden')
60+
elements.profileLink.innerText = session.webId
61+
elements.profileLink.href = session.webId
62+
}
63+
})
64+
</script>
3465
</body>
3566
</html>

0 commit comments

Comments
 (0)