puerta/internal/user/credential.go

31 lines
627 B
Go
Raw Normal View History

2023-01-04 04:21:49 +00:00
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2022 Roberto Hidalgo <nidito@un.rob.mx>
package user
import (
"encoding/json"
"github.com/go-webauthn/webauthn/webauthn"
2023-04-16 21:17:36 +00:00
"github.com/upper/db/v4"
2023-01-04 04:21:49 +00:00
)
type Credential struct {
UserID int `db:"user"`
Data string `db:"data"`
wan *webauthn.Credential
}
func (c *Credential) AsWebAuthn() webauthn.Credential {
if c.wan == nil {
c.wan = &webauthn.Credential{}
if err := json.Unmarshal([]byte(c.Data), &c.wan); err != nil {
panic(err)
}
}
return *c.wan
}
2023-04-16 21:17:36 +00:00
func (c *Credential) Store(sess db.Session) db.Store {
return sess.Collection("credential")
}