diff --git a/pkg/baseurl/baseurl.go b/pkg/baseurl/baseurl.go index e2ebeb506..9417ea91c 100644 --- a/pkg/baseurl/baseurl.go +++ b/pkg/baseurl/baseurl.go @@ -116,15 +116,12 @@ type URLBuilder struct { } // WithPath returns a URLBuilder with the specified path. -// The path will be properly joined with the base URL. +// The path will be properly joined with the base URL's path. func (b *BaseURL) WithPath(path string) *URLBuilder { if b == nil { return &URLBuilder{err: fmt.Errorf("base URL is nil")} } - // Ensure path does not end with / - basePath := strings.TrimSuffix(b.parsed.Path, "/") - // Ensure path starts with / if !strings.HasPrefix(path, "/") { path = "/" + path @@ -135,30 +132,11 @@ func (b *BaseURL) WithPath(path string) *URLBuilder { return &URLBuilder{ base: b, - path: basePath + path, + path: path, query: make(url.Values), } } -// WithPath returns a URLBuilder with the specified path. -// The path will be properly joined with the base URL. -func (ub *URLBuilder) WithPath(path string) *URLBuilder { - if ub == nil { - return ub - } - - // Ensure path starts with / - if !strings.HasPrefix(path, "/") { - path = "/" + path - } - - // Ensure path does not end with / - path = strings.TrimSuffix(path, "/") - - ub.path = ub.path + path - return ub -} - // WithQuery adds a query parameter to the URL. func (ub *URLBuilder) WithQuery(key, value string) *URLBuilder { if ub.err != nil { diff --git a/pkg/iam/auth_service.go b/pkg/iam/auth_service.go index 90d3c2af1..f26b047fe 100644 --- a/pkg/iam/auth_service.go +++ b/pkg/iam/auth_service.go @@ -64,7 +64,7 @@ type ( SendMagicLinkRequest struct { Email mail.Addr - BaseURL *baseurl.BaseURL + BaseURL *baseurl.URLBuilder } PasswordResetData struct { @@ -560,7 +560,6 @@ func (s AuthService) SendMagicLink(ctx context.Context, req *SendMagicLinkReques } magicLinkURL := req.BaseURL. - WithPath("/verify-magic-link"). WithQuery("token", token). MustString() diff --git a/pkg/server/api/trust/v1/v1_resolver.go b/pkg/server/api/trust/v1/v1_resolver.go index de1c4f3cd..e4faadac9 100644 --- a/pkg/server/api/trust/v1/v1_resolver.go +++ b/pkg/server/api/trust/v1/v1_resolver.go @@ -165,11 +165,7 @@ func (r *mutationResolver) SendMagicLink(ctx context.Context, input types.SendMa } customDomain, err := r.trust.GetCustomDomainByOrganizationID(ctx, organization.ID) - if err != nil { - if errors.Is(err, trust.ErrCustomDomainNotFound) { - return nil, gqlutils.NotFoundf(ctx, "custom domain not found") - } - + if err != nil && !errors.Is(err, trust.ErrCustomDomainNotFound) { r.logger.ErrorCtx(ctx, "cannot get custom domain", log.Error(err)) return nil, gqlutils.Internal(ctx) } @@ -185,15 +181,11 @@ func (r *mutationResolver) SendMagicLink(ctx context.Context, input types.SendMa return nil, gqlutils.Internal(ctx) } - req.BaseURL = baseURL + req.BaseURL = baseURL.WithPath("/verify-magic-link") } else { - baseURL, err := baseurl.Parse(r.baseURL.WithPath("/trust/" + trustCenter.ID.String()).MustString()) - if err != nil { - r.logger.ErrorCtx(ctx, "cannot parse url", log.Error(err)) - return nil, gqlutils.Internal(ctx) - } - - req.BaseURL = baseURL + req.BaseURL = r.baseURL.WithPath( + fmt.Sprintf("/trust/%s/verify-magic-link", trustCenter.ID.String()), + ) } if err := r.iam.AuthService.SendMagicLink(ctx, req); err != nil {