Resolves #19
This commit is contained in:
parent
27264c6e29
commit
65fb655f66
|
@ -70,10 +70,6 @@ type ComplexityRoot struct {
|
|||
Users func(childComplexity int) int
|
||||
}
|
||||
|
||||
Response struct {
|
||||
Message func(childComplexity int) int
|
||||
}
|
||||
|
||||
User struct {
|
||||
CreatedAt func(childComplexity int) int
|
||||
Email func(childComplexity int) int
|
||||
|
@ -99,7 +95,7 @@ type ComplexityRoot struct {
|
|||
}
|
||||
|
||||
type MutationResolver interface {
|
||||
VerifySignupToken(ctx context.Context, params model.VerifySignupTokenInput) (*model.Response, error)
|
||||
VerifySignupToken(ctx context.Context, params model.VerifySignupTokenInput) (*model.LoginResponse, error)
|
||||
BasicAuthSignUp(ctx context.Context, params model.BasicAuthSignupInput) (*model.BasicAuthSignupResponse, error)
|
||||
Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse, error)
|
||||
}
|
||||
|
@ -222,13 +218,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
|
||||
return e.complexity.Query.Users(childComplexity), true
|
||||
|
||||
case "Response.message":
|
||||
if e.complexity.Response.Message == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.Response.Message(childComplexity), true
|
||||
|
||||
case "User.createdAt":
|
||||
if e.complexity.User.CreatedAt == nil {
|
||||
break
|
||||
|
@ -445,10 +434,6 @@ type Error {
|
|||
reason: String!
|
||||
}
|
||||
|
||||
type Response {
|
||||
message: String!
|
||||
}
|
||||
|
||||
type LoginResponse {
|
||||
message: String!
|
||||
accessToken: String
|
||||
|
@ -479,7 +464,7 @@ input VerifySignupTokenInput {
|
|||
}
|
||||
|
||||
type Mutation {
|
||||
verifySignupToken(params: VerifySignupTokenInput!): Response!
|
||||
verifySignupToken(params: VerifySignupTokenInput!): LoginResponse!
|
||||
basicAuthSignUp(params: BasicAuthSignupInput!): BasicAuthSignupResponse!
|
||||
login(params: LoginInput!): LoginResponse!
|
||||
}
|
||||
|
@ -867,9 +852,9 @@ func (ec *executionContext) _Mutation_verifySignupToken(ctx context.Context, fie
|
|||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*model.Response)
|
||||
res := resTmp.(*model.LoginResponse)
|
||||
fc.Result = res
|
||||
return ec.marshalNResponse2ᚖgithubᚗcomᚋyauthdevᚋyauthᚋserverᚋgraphᚋmodelᚐResponse(ctx, field.Selections, res)
|
||||
return ec.marshalNLoginResponse2ᚖgithubᚗcomᚋyauthdevᚋyauthᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_basicAuthSignUp(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
|
@ -1094,41 +1079,6 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C
|
|||
return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Response_message(ctx context.Context, field graphql.CollectedField, obj *model.Response) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "Response",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Message, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -3076,33 +3026,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
|
|||
return out
|
||||
}
|
||||
|
||||
var responseImplementors = []string{"Response"}
|
||||
|
||||
func (ec *executionContext) _Response(ctx context.Context, sel ast.SelectionSet, obj *model.Response) graphql.Marshaler {
|
||||
fields := graphql.CollectFields(ec.OperationContext, sel, responseImplementors)
|
||||
|
||||
out := graphql.NewFieldSet(fields)
|
||||
var invalids uint32
|
||||
for i, field := range fields {
|
||||
switch field.Name {
|
||||
case "__typename":
|
||||
out.Values[i] = graphql.MarshalString("Response")
|
||||
case "message":
|
||||
out.Values[i] = ec._Response_message(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
}
|
||||
out.Dispatch()
|
||||
if invalids > 0 {
|
||||
return graphql.Null
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
var userImplementors = []string{"User"}
|
||||
|
||||
func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *model.User) graphql.Marshaler {
|
||||
|
@ -3506,20 +3429,6 @@ func (ec *executionContext) marshalNLoginResponse2ᚖgithubᚗcomᚋyauthdevᚋy
|
|||
return ec._LoginResponse(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNResponse2githubᚗcomᚋyauthdevᚋyauthᚋserverᚋgraphᚋmodelᚐResponse(ctx context.Context, sel ast.SelectionSet, v model.Response) graphql.Marshaler {
|
||||
return ec._Response(ctx, sel, &v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNResponse2ᚖgithubᚗcomᚋyauthdevᚋyauthᚋserverᚋgraphᚋmodelᚐResponse(ctx context.Context, sel ast.SelectionSet, v *model.Response) graphql.Marshaler {
|
||||
if v == nil {
|
||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
return ec._Response(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) {
|
||||
res, err := graphql.UnmarshalString(v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
|
|
|
@ -32,10 +32,6 @@ type LoginResponse struct {
|
|||
User *User `json:"user"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
|
|
|
@ -31,10 +31,6 @@ type Error {
|
|||
reason: String!
|
||||
}
|
||||
|
||||
type Response {
|
||||
message: String!
|
||||
}
|
||||
|
||||
type LoginResponse {
|
||||
message: String!
|
||||
accessToken: String
|
||||
|
@ -65,7 +61,7 @@ input VerifySignupTokenInput {
|
|||
}
|
||||
|
||||
type Mutation {
|
||||
verifySignupToken(params: VerifySignupTokenInput!): Response!
|
||||
verifySignupToken(params: VerifySignupTokenInput!): LoginResponse!
|
||||
basicAuthSignUp(params: BasicAuthSignupInput!): BasicAuthSignupResponse!
|
||||
login(params: LoginInput!): LoginResponse!
|
||||
}
|
||||
|
|
|
@ -20,10 +20,14 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) VerifySignupToken(ctx context.Context, params model.VerifySignupTokenInput) (*model.Response, error) {
|
||||
// // verify if token is valid
|
||||
var res *model.Response
|
||||
_, err := db.Mgr.GetVerificationByToken(params.Token)
|
||||
func (r *mutationResolver) VerifySignupToken(ctx context.Context, params model.VerifySignupTokenInput) (*model.LoginResponse, error) {
|
||||
gc, err := utils.GinContextFromContext(ctx)
|
||||
var res *model.LoginResponse
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
_, err = db.Mgr.GetVerificationByToken(params.Token)
|
||||
if err != nil {
|
||||
return res, errors.New(`Invalid token`)
|
||||
}
|
||||
|
@ -33,15 +37,44 @@ func (r *mutationResolver) VerifySignupToken(ctx context.Context, params model.V
|
|||
if err != nil {
|
||||
return res, errors.New(`Invalid token`)
|
||||
}
|
||||
res = &model.Response{
|
||||
Message: `Email verified successfully. Login to access the system.`,
|
||||
}
|
||||
|
||||
// update email_verified_at in users table
|
||||
db.Mgr.UpdateVerificationTime(time.Now().Unix(), claim.Email)
|
||||
// delete from verification table
|
||||
db.Mgr.DeleteToken(claim.Email)
|
||||
|
||||
user, err := db.Mgr.GetUserByEmail(claim.Email)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
userIdStr := fmt.Sprintf("%d", user.ID)
|
||||
refreshToken, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||
ID: userIdStr,
|
||||
Email: user.Email,
|
||||
}, enum.RefreshToken)
|
||||
|
||||
accessToken, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||
ID: userIdStr,
|
||||
Email: user.Email,
|
||||
}, enum.AccessToken)
|
||||
|
||||
session.SetToken(userIdStr, refreshToken)
|
||||
|
||||
res = &model.LoginResponse{
|
||||
Message: `Email verified successfully.`,
|
||||
AccessToken: &accessToken,
|
||||
User: &model.User{
|
||||
ID: userIdStr,
|
||||
Email: user.Email,
|
||||
Image: &user.Image,
|
||||
FirstName: &user.FirstName,
|
||||
LastName: &user.LastName,
|
||||
},
|
||||
}
|
||||
|
||||
utils.SetCookie(gc, accessToken)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
@ -137,7 +170,6 @@ func (r *mutationResolver) Login(ctx context.Context, params model.LoginInput) (
|
|||
return res, errors.New(`Invalid Password`)
|
||||
}
|
||||
userIdStr := fmt.Sprintf("%d", user.ID)
|
||||
log.Println("session object init -> ", session.GetToken(userIdStr))
|
||||
refreshToken, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||
ID: userIdStr,
|
||||
Email: user.Email,
|
||||
|
@ -149,7 +181,6 @@ func (r *mutationResolver) Login(ctx context.Context, params model.LoginInput) (
|
|||
}, enum.AccessToken)
|
||||
|
||||
session.SetToken(userIdStr, refreshToken)
|
||||
log.Println("session object -> ", session.GetToken(userIdStr))
|
||||
|
||||
res = &model.LoginResponse{
|
||||
Message: `Logged in successfully`,
|
||||
|
@ -200,7 +231,5 @@ func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResol
|
|||
// Query returns generated.QueryResolver implementation.
|
||||
func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
|
||||
|
||||
type (
|
||||
mutationResolver struct{ *Resolver }
|
||||
queryResolver struct{ *Resolver }
|
||||
)
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
|
|
Loading…
Reference in New Issue
Block a user