Skip to content

Commit af2762a

Browse files
authored
Set up the session for solid-auth-client w/ tls (#596)
1 parent ac9d4a3 commit af2762a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

default-views/auth/login-tls.hbs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,29 @@
88
{{> auth/auth-hidden-fields}}
99
</div>
1010
</form>
11+
12+
<script type="text/javascript">
13+
const button = document.getElementById('login-tls')
14+
button.addEventListener('click', function(event) {
15+
event.preventDefault()
16+
fetch('/login/tls', { method: 'POST', credentials: 'include' })
17+
.then(function(response) {
18+
const webId = response.headers.get('user')
19+
const idp = new URL(webId).origin
20+
const session = { authType: 'WebID-TLS', webId, idp }
21+
const authClientNamespace = 'solid-auth-client'
22+
let authClientStore
23+
try {
24+
authClientStore = JSON.parse(localStorage.getItem(authClientNamespace) || '{}')
25+
} catch (err) {
26+
authClientStore = {}
27+
}
28+
authClientStore.session = session
29+
localStorage.setItem(authClientNamespace, JSON.stringify(authClientStore))
30+
return response
31+
})
32+
.then(function(response) {
33+
window.location.href = response.url
34+
})
35+
})
36+
</script>

0 commit comments

Comments
 (0)