Change magic link request to use url builder
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user