add signup resolver

This commit is contained in:
Lakhan Samani
2021-07-12 23:52:16 +05:30
parent 54bb923e9a
commit 04a522c947
19 changed files with 2828 additions and 311 deletions

View File

@@ -0,0 +1,49 @@
package utils
import (
"time"
"github.com/golang-jwt/jwt"
"github.com/yauthdev/yauth/server/constants"
)
type UserInfo struct {
Email string `json:"email"`
}
type CustomClaimsExample struct {
*jwt.StandardClaims
TokenType string `json:"token_type"`
UserInfo
}
// TODO convert tokenType to enum
func CreateVerificationToken(email string, tokenType string) (string, error) {
t := jwt.New(jwt.GetSigningMethod(constants.JWT_TYPE))
t.Claims = &CustomClaimsExample{
&jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
},
tokenType,
UserInfo{Email: email},
}
return t.SignedString([]byte(constants.JWT_SECRET))
}
func VerifyVerificationToken(email string, tokenType string) (string, error) {
t := jwt.New(jwt.GetSigningMethod(constants.JWT_TYPE))
t.Claims = &CustomClaimsExample{
&jwt.StandardClaims{
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
},
tokenType,
UserInfo{Email: email},
}
return t.SignedString([]byte(constants.JWT_SECRET))
}