first commit
This commit is contained in:
41
models/accounts.go
Normal file
41
models/accounts.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
ID string `json:"id"`
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
VerifiedIdentity *bool `json:"verifiedIdentity,omitempty"`
|
||||
BirthDate string `json:"birthdate,omitempty"`
|
||||
LocalCredentials
|
||||
}
|
||||
|
||||
type LocalCredentials struct {
|
||||
Email string
|
||||
EmailVerified bool
|
||||
EmailValidationCode string
|
||||
PhoneNumber string
|
||||
PhoneNumberVerified bool
|
||||
PhoneNumberValidationCode string
|
||||
}
|
||||
|
||||
type UserClaims struct {
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
func (account Account) CreateToken(ttl time.Duration, key string) (token string, err error) {
|
||||
expires_at := jwt.NewNumericDate(time.Now().Add(ttl))
|
||||
claims := UserClaims{
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
Subject: account.Email,
|
||||
ExpiresAt: expires_at,
|
||||
},
|
||||
}
|
||||
|
||||
t := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return t.SignedString([]byte(key))
|
||||
}
|
||||
Reference in New Issue
Block a user