11
11
< div class ="container ">
12
12
< div class ="page-header ">
13
13
< 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 >
17
15
18
- < a href ="/login " class ="btn btn-success ">
19
- Login
20
- </ a >
16
+ < a onclick ="login() " class ="btn btn-success "> Login</ a >
21
17
</ div >
22
18
23
19
< h1 > Welcome to the Solid Prototype</ h1 >
@@ -30,6 +26,41 @@ <h1>Welcome to the Solid Prototype</h1>
30
26
31
27
If you have not already done so, please create an account.
32
28
</ p >
29
+
30
+ < p class ="lead hidden " id ="loggedIn ">
31
+ You are logged in as
32
+ < a href ="# " id ="profileLink "> </ a > .
33
+ </ p >
33
34
</ 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 >
34
65
</ body >
35
66
</ html >
0 commit comments