From 5220d7fadeba503263e783f8f97b071a35ebe357 Mon Sep 17 00:00:00 2001 From: Daniel Joudat Date: Mon, 13 Dec 2021 21:47:24 +0300 Subject: [PATCH] fix an error when calling VerifyToken with valid Token (#327) * add two rpcs to User service: - Passwordless: endpoint that receives an email, topic and an optional message - PasswordlessML: endpoint that receives token and topic via MagicLink. * Proposal to add Passwordless login feature to the endpoint user. * remove currency run check * Commit from GitHub Actions (Publish APIs & Clients) * Create downstream.yml * Commit from GitHub Actions (Publish APIs & Clients) * update todo * Commit from GitHub Actions (Publish APIs & Clients) * Update publish.yml * Commit from GitHub Actions (Publish APIs & Clients) * Update publish.yml * Commit from GitHub Actions (Publish APIs & Clients) * Update and rename publish.yml to generate.yml * Update generate.yml * Commit from GitHub Actions (Generate Clients & Examples) * Commit from GitHub Actions (Generate Clients & Examples) * add comments * Commit from GitHub Actions (Generate Clients & Examples) * move otp to auth category * charge for user verification * Commit from GitHub Actions (Generate Clients & Examples) * Update user.proto * Commit from GitHub Actions (Generate Clients & Examples) * Commit from GitHub Actions (Generate Clients & Examples) * Change js client git repo url (#249) * Commit from GitHub Actions (Generate Clients & Examples) * use tableName func for Count * Commit from GitHub Actions (Generate Clients & Examples) * update notes example * Commit from GitHub Actions (Generate Clients & Examples) * Update .gitignore * Update .gitignore * Commit from GitHub Actions (Generate Clients & Examples) * add new endpoints SendMagicLink and VerifyToken to M3O user serivce Signed-off-by: Daniel Joudat * fix an error in user.VerifyToken Signed-off-by: Daniel Joudat * OSD add another check for err in user CacheReadToken Signed-off-by: Daniel Joudat Co-authored-by: Asim Aslam Co-authored-by: asim Co-authored-by: Janos Dobronszki Co-authored-by: crufter --- user/domain/domain.go | 2 +- user/handler/handler.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/user/domain/domain.go b/user/domain/domain.go index 8a42fd5..4cbd14d 100644 --- a/user/domain/domain.go +++ b/user/domain/domain.go @@ -501,7 +501,7 @@ func (domain *Domain) CacheReadToken(ctx context.Context, token string) (string, expires, err := cache.Context(ctx).Get(token, email) - if err == cache.ErrNotFound { + if err != nil && err == cache.ErrNotFound { return "", errors.New("token not found") } else if time.Until(expires).Seconds() < 0 { return "", errors.New("token expired") diff --git a/user/handler/handler.go b/user/handler/handler.go index cac0129..14a1f34 100644 --- a/user/handler/handler.go +++ b/user/handler/handler.go @@ -437,15 +437,15 @@ func (s *User) VerifyToken(ctx context.Context, req *pb.VerifyTokenRequest, rsp // check if token is valid email, err := s.domain.CacheReadToken(ctx, token) - if err.Error() == "token not found" { + if err != nil && err.Error() == "token not found" { rsp.IsValid = false rsp.Message = err.Error() return nil - } else if err.Error() == "token expired" { + } else if err != nil && err.Error() == "token expired" { rsp.IsValid = false rsp.Message = err.Error() return nil - } else if err.Error() == "token empty" { + } else if err != nil && err.Error() == "token empty" { rsp.IsValid = false rsp.Message = err.Error() return nil