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 @@
{data.user.discord}
).
+ {:else}
+ You do not have a linked Discord account.
+ {/if}
+ {data.user.discord}
).
- {:else}
- You do not have a linked Discord account.
+
+ {:else if data.urls.discord}
+
{/if}
-
- {#if data.user.discord}
-
- {:else}
-
- {/if}
- {data.user.tumblr}
).
+ {:else}
+ You do not have a linked Tumblr account.
+ {/if}
+ {data.user.tumblr}
).
- {:else}
- You do not have a linked Tumblr account.
+
+ {:else if data.urls.tumblr}
+
{/if}
-
- {#if data.user.tumblr}
-
- {:else}
-
- {/if}
- {data.user.google}
).
+ {:else}
+ You do not have a linked Google account.
+ {/if}
+ {data.user.google}
).
- {:else}
- You do not have a linked Google account.
+
+ {:else if data.urls.google}
+
{/if}
-
- {#if data.user.google}
-
- {:else}
-
- {/if}
-