Skip to content

Commit

Permalink
Persist kthid for passkey login in localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
foodelevator committed Nov 8, 2024
1 parent efd2052 commit 78ba056
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func index(s *service.Service, w http.ResponseWriter, r *http.Request) httputil.
SameSite: http.SameSiteLaxMode,
})
}
return templates.Index(s.PasskeyLogin(), s.DevLoginForm)
return templates.Index(s.DevLoginForm)
}

func logout(s *service.Service, w http.ResponseWriter, r *http.Request) httputil.ToResponse {
Expand Down
4 changes: 0 additions & 4 deletions pkg/static/public/style.dist.css
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,6 @@ html {
width: 100%;
}

.w-20 {
width: 5rem;
}

.max-w-\[calc\(100vw-2rem\)\] {
max-width: calc(100vw - 2rem);
}
Expand Down
6 changes: 0 additions & 6 deletions service/passkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"context"
"encoding/json"

"github.com/a-h/templ"
"github.com/datasektionen/logout/models"
"github.com/datasektionen/logout/pkg/config"
"github.com/datasektionen/logout/templates"
"github.com/go-webauthn/webauthn/webauthn"
)

Expand Down Expand Up @@ -38,7 +36,3 @@ func (s *Service) ListPasskeysForUser(ctx context.Context, kthid string) ([]mode
}
return passkeys, nil
}

func (s *Service) PasskeyLogin() func() templ.Component {
return func() templ.Component { return templates.PasskeyLoginForm("", nil) }
}
5 changes: 4 additions & 1 deletion templates/passkey.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ templ PasskeyLoginForm(kthid string, credAss *protocol.CredentialAssertion) {
<form
id="passkey-login-form"
hx-post="/login/passkey/begin"
hx-on::before-request="this.querySelectorAll('.error').forEach(e => e.remove())"
_="
on load if localStorage.logout_saved_kthid then set #pk-kthid.value to localStorage.logout_saved_kthid end
on submit remove <.error/> then if #pk-kthid.value then set localStorage.logout_saved_kthid to #pk-kthid.value
"
if credAss != nil {
data-cred-ass={ templ.JSONString(credAss) }
}
Expand Down
12 changes: 6 additions & 6 deletions templates/passkey_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions templates/user.templ
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"
)

templ Index(passkeyLogin func() templ.Component, devLogin func() templ.Component) {
templ Index(devLogin func() templ.Component) {
@modal() {
<div class="p-8 flex flex-col gap-4">
<img class="h-40 pb-4 block" src="/public/skold_vit.svg"/>
Expand All @@ -18,7 +18,7 @@ templ Index(passkeyLogin func() templ.Component, devLogin func() templ.Component
focus:border-cerise-strong hover:border-cerise-light
"
>Log In with KTH</a>
@passkeyLogin()
@PasskeyLoginForm("", nil)
@devLogin()
</div>
}
Expand Down
4 changes: 2 additions & 2 deletions templates/user_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78ba056

Please sign in to comment.