-
Notifications
You must be signed in to change notification settings - Fork 938
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix user import with multiple credentials
Fix user import with multiple credential and the same user handle. Check if the user handle already exists and associate the credential with it otherwise create a new user handle in the database.
- Loading branch information
1 parent
dadfbde
commit 306db83
Showing
3 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
backend/persistence/webauthn_credential_user_handle_persister.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package persistence | ||
|
||
import ( | ||
"database/sql" | ||
"errors" | ||
"fmt" | ||
"github.com/gobuffalo/pop/v6" | ||
"github.com/teamhanko/hanko/backend/persistence/models" | ||
) | ||
|
||
type WebauthnCredentialUserHandlePersister interface { | ||
GetByHandle(string) (*models.WebauthnCredentialUserHandle, error) | ||
} | ||
|
||
func NewWebauthnCredentialUserHandlePersister(db *pop.Connection) WebauthnCredentialUserHandlePersister { | ||
return &webauthnCredentialUserHandlePersister{db: db} | ||
} | ||
|
||
type webauthnCredentialUserHandlePersister struct { | ||
db *pop.Connection | ||
} | ||
|
||
func (p *webauthnCredentialUserHandlePersister) GetByHandle(handle string) (*models.WebauthnCredentialUserHandle, error) { | ||
handleModel := models.WebauthnCredentialUserHandle{} | ||
err := p.db.Where("handle = ?", handle).First(&handleModel) | ||
if err != nil && errors.Is(err, sql.ErrNoRows) { | ||
return nil, nil | ||
} | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get handleModel: %w", err) | ||
} | ||
|
||
return &handleModel, nil | ||
} |