diff --git a/backend/routes/auth/routes.go b/backend/routes/auth/routes.go index 7fec89c..1b7ad53 100644 --- a/backend/routes/auth/routes.go +++ b/backend/routes/auth/routes.go @@ -144,9 +144,9 @@ type oauthURLsRequest struct { } type oauthURLsResponse struct { - Discord string `json:"discord"` - Tumblr string `json:"tumblr"` - Google string `json:"google"` + Discord string `json:"discord,omitempty"` + Tumblr string `json:"tumblr,omitempty"` + Google string `json:"google,omitempty"` } func (s *Server) oauthURLs(w http.ResponseWriter, r *http.Request) error { @@ -162,22 +162,25 @@ func (s *Server) oauthURLs(w http.ResponseWriter, r *http.Request) error { if err != nil { return errors.Wrap(err, "setting CSRF state") } + var resp oauthURLsResponse - // copy Discord config and set redirect url - discordCfg := discordOAuthConfig - discordCfg.RedirectURL = req.CallbackDomain + "/auth/login/discord" - // copy tumblr config - tumblrCfg := tumblrOAuthConfig - tumblrCfg.RedirectURL = req.CallbackDomain + "/auth/login/tumblr" - // copy google config - googleCfg := googleOAuthConfig - googleCfg.RedirectURL = req.CallbackDomain + "/auth/login/google" + if discordOAuthConfig.ClientID != "" { + discordCfg := discordOAuthConfig + discordCfg.RedirectURL = req.CallbackDomain + "/auth/login/discord" + resp.Discord = discordCfg.AuthCodeURL(state) + "&prompt=none" + } + if tumblrOAuthConfig.ClientID != "" { + tumblrCfg := tumblrOAuthConfig + tumblrCfg.RedirectURL = req.CallbackDomain + "/auth/login/tumblr" + resp.Tumblr = tumblrCfg.AuthCodeURL(state) + } + if googleOAuthConfig.ClientID != "" { + googleCfg := googleOAuthConfig + googleCfg.RedirectURL = req.CallbackDomain + "/auth/login/google" + resp.Google = googleCfg.AuthCodeURL(state) + } - render.JSON(w, r, oauthURLsResponse{ - Discord: discordCfg.AuthCodeURL(state) + "&prompt=none", - Tumblr: tumblrCfg.AuthCodeURL(state), - Google: googleCfg.AuthCodeURL(state), - }) + render.JSON(w, r, resp) return nil } diff --git a/frontend/src/lib/api/responses.ts b/frontend/src/lib/api/responses.ts index 561deba..9af4647 100644 --- a/frontend/src/lib/api/responses.ts +++ b/frontend/src/lib/api/responses.ts @@ -14,9 +14,9 @@ export interface MetaResponse { } export interface UrlsResponse { - discord: string; - tumblr: string; - google: string; + discord?: string; + tumblr?: string; + google?: string; } export interface ExportResponse { diff --git a/frontend/src/routes/auth/login/+page.svelte b/frontend/src/routes/auth/login/+page.svelte index c7ee00b..528f7c0 100644 --- a/frontend/src/routes/auth/login/+page.svelte +++ b/frontend/src/routes/auth/login/+page.svelte @@ -60,9 +60,15 @@
Log in with the Fediverse - Log in with Discord - Log in with Tumblr - Log in with Google + {#if data.discord} + Log in with Discord + {/if} + {#if data.tumblr} + Log in with Tumblr + {/if} + {#if data.google} + Log in with Google + {/if} diff --git a/frontend/src/routes/settings/auth/+page.svelte b/frontend/src/routes/settings/auth/+page.svelte index 59dfb03..7c10704 100644 --- a/frontend/src/routes/settings/auth/+page.svelte +++ b/frontend/src/routes/settings/auth/+page.svelte @@ -132,72 +132,78 @@
-
- - - Discord - + {#if data.user.discord || data.urls.discord} +
+ + + Discord + + {#if data.user.discord} + Your currently linked Discord account is {data.user.discord_username} + ({data.user.discord}). + {:else} + You do not have a linked Discord account. + {/if} + {#if data.user.discord} - Your currently linked Discord account is {data.user.discord_username} - ({data.user.discord}). - {:else} - You do not have a linked Discord account. + + {:else if data.urls.discord} + {/if} - - {#if data.user.discord} - - {:else} - - {/if} - - -
-
- - - Tumblr - + + +
+ {/if} + {#if data.user.tumblr || data.urls.tumblr} +
+ + + Tumblr + + {#if data.user.tumblr} + Your currently linked Tumblr account is {data.user.tumblr_username} + ({data.user.tumblr}). + {:else} + You do not have a linked Tumblr account. + {/if} + {#if data.user.tumblr} - Your currently linked Tumblr account is {data.user.tumblr_username} - ({data.user.tumblr}). - {:else} - You do not have a linked Tumblr account. + + {:else if data.urls.tumblr} + {/if} - - {#if data.user.tumblr} - - {:else} - - {/if} - - -
-
- - - Google - + + +
+ {/if} + {#if data.user.google || data.urls.google} +
+ + + Google + + {#if data.user.google} + Your currently linked Google account is {data.user.google_username} + ({data.user.google}). + {:else} + You do not have a linked Google account. + {/if} + {#if data.user.google} - Your currently linked Google account is {data.user.google_username} - ({data.user.google}). - {:else} - You do not have a linked Google account. + + {:else if data.urls.google} + {/if} - - {#if data.user.google} - - {:else} - - {/if} - - -
+
+
+
+ {/if}