Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip pushing site url config for localhost #2949

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pkg/config/auth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"net"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -217,9 +219,17 @@ type (
}
)

func isLoopbackURL(siteURL string) bool {
if parsed, err := url.Parse(siteURL); err == nil {
if ip := net.ParseIP(parsed.Hostname()); ip != nil {
return ip.IsLoopback()
}
}
return false
}
Comment on lines +222 to +229
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick

Wonder if it might cause issue if you use local aliase like localhost.
But that'll probably work for most of the setup.


func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
body := v1API.UpdateAuthConfigBody{
SiteUrl: &a.SiteUrl,
UriAllowList: cast.Ptr(strings.Join(a.AdditionalRedirectUrls, ",")),
JwtExp: cast.UintToIntPtr(&a.JwtExpiry),
RefreshTokenRotationEnabled: &a.EnableRefreshTokenRotation,
Expand All @@ -230,6 +240,9 @@ func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
PasswordMinLength: cast.UintToIntPtr(&a.MinimumPasswordLength),
PasswordRequiredCharacters: cast.Ptr(a.PasswordRequirements.ToChar()),
}
if !isLoopbackURL(a.SiteUrl) {
body.SiteUrl = &a.SiteUrl
}
a.Hook.toAuthConfigBody(&body)
a.MFA.toAuthConfigBody(&body)
a.Sessions.toAuthConfigBody(&body)
Expand All @@ -240,7 +253,6 @@ func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
}

func (a *auth) FromRemoteAuthConfig(remoteConfig v1API.AuthConfigResponse) {
a.SiteUrl = cast.Val(remoteConfig.SiteUrl, "")
a.AdditionalRedirectUrls = strToArr(cast.Val(remoteConfig.UriAllowList, ""))
a.JwtExpiry = cast.IntToUint(cast.Val(remoteConfig.JwtExp, 0))
a.EnableRefreshTokenRotation = cast.Val(remoteConfig.RefreshTokenRotationEnabled, false)
Expand All @@ -251,6 +263,9 @@ func (a *auth) FromRemoteAuthConfig(remoteConfig v1API.AuthConfigResponse) {
a.MinimumPasswordLength = cast.IntToUint(cast.Val(remoteConfig.PasswordMinLength, 0))
prc := cast.Val(remoteConfig.PasswordRequiredCharacters, "")
a.PasswordRequirements = NewPasswordRequirement(v1API.UpdateAuthConfigBodyPasswordRequiredCharacters(prc))
if !isLoopbackURL(a.SiteUrl) {
a.SiteUrl = cast.Val(remoteConfig.SiteUrl, "")
}
a.Hook.fromAuthConfig(remoteConfig)
a.MFA.fromAuthConfig(remoteConfig)
a.Sessions.fromAuthConfig(remoteConfig)
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/templates/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ enabled = true
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
# in emails.
site_url = "http://127.0.0.1:3000"
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
additional_redirect_urls = ["https://127.0.0.1:3000"]
# A list of URLs that auth providers are permitted to redirect to post authentication.
# Supports wildcard matching: "https://127.0.0.1:3000/app/**"
additional_redirect_urls = []
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
jwt_expiry = 3600
# If disabled, the refresh token will never expire.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ diff remote[auth] local[auth]
+++ local[auth]
@@ -1,14 +1,14 @@
enabled = false
-site_url = ""
site_url = "http://127.0.0.1:3000"
-additional_redirect_urls = ["https://127.0.0.1:3000", "https://ref.supabase.co"]
sweatybridge marked this conversation as resolved.
Show resolved Hide resolved
-jwt_expiry = 0
-enable_refresh_token_rotation = true
Expand All @@ -13,7 +13,6 @@ diff remote[auth] local[auth]
-enable_anonymous_sign_ins = true
-minimum_password_length = 8
-password_requirements = "letters_digits"
+site_url = "http://127.0.0.1:3000"
+additional_redirect_urls = ["https://127.0.0.1:3000"]
+jwt_expiry = 3600
+enable_refresh_token_rotation = false
Expand Down
Loading