feat: only show auth providers if they're enabled
This commit is contained in:
parent
17f2552c6a
commit
f5d7bc4095
4 changed files with 98 additions and 83 deletions
|
@ -144,9 +144,9 @@ type oauthURLsRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type oauthURLsResponse struct {
|
type oauthURLsResponse struct {
|
||||||
Discord string `json:"discord"`
|
Discord string `json:"discord,omitempty"`
|
||||||
Tumblr string `json:"tumblr"`
|
Tumblr string `json:"tumblr,omitempty"`
|
||||||
Google string `json:"google"`
|
Google string `json:"google,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) oauthURLs(w http.ResponseWriter, r *http.Request) error {
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "setting CSRF state")
|
return errors.Wrap(err, "setting CSRF state")
|
||||||
}
|
}
|
||||||
|
var resp oauthURLsResponse
|
||||||
|
|
||||||
// copy Discord config and set redirect url
|
if discordOAuthConfig.ClientID != "" {
|
||||||
discordCfg := discordOAuthConfig
|
discordCfg := discordOAuthConfig
|
||||||
discordCfg.RedirectURL = req.CallbackDomain + "/auth/login/discord"
|
discordCfg.RedirectURL = req.CallbackDomain + "/auth/login/discord"
|
||||||
// copy tumblr config
|
resp.Discord = discordCfg.AuthCodeURL(state) + "&prompt=none"
|
||||||
tumblrCfg := tumblrOAuthConfig
|
}
|
||||||
tumblrCfg.RedirectURL = req.CallbackDomain + "/auth/login/tumblr"
|
if tumblrOAuthConfig.ClientID != "" {
|
||||||
// copy google config
|
tumblrCfg := tumblrOAuthConfig
|
||||||
googleCfg := googleOAuthConfig
|
tumblrCfg.RedirectURL = req.CallbackDomain + "/auth/login/tumblr"
|
||||||
googleCfg.RedirectURL = req.CallbackDomain + "/auth/login/google"
|
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{
|
render.JSON(w, r, resp)
|
||||||
Discord: discordCfg.AuthCodeURL(state) + "&prompt=none",
|
|
||||||
Tumblr: tumblrCfg.AuthCodeURL(state),
|
|
||||||
Google: googleCfg.AuthCodeURL(state),
|
|
||||||
})
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ export interface MetaResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UrlsResponse {
|
export interface UrlsResponse {
|
||||||
discord: string;
|
discord?: string;
|
||||||
tumblr: string;
|
tumblr?: string;
|
||||||
google: string;
|
google?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExportResponse {
|
export interface ExportResponse {
|
||||||
|
|
|
@ -60,9 +60,15 @@
|
||||||
<div class="col-md-4 mb-1">
|
<div class="col-md-4 mb-1">
|
||||||
<ListGroup>
|
<ListGroup>
|
||||||
<ListGroupItem tag="button" on:click={toggleModal}>Log in with the Fediverse</ListGroupItem>
|
<ListGroupItem tag="button" on:click={toggleModal}>Log in with the Fediverse</ListGroupItem>
|
||||||
<ListGroupItem tag="a" href={data.discord}>Log in with Discord</ListGroupItem>
|
{#if data.discord}
|
||||||
<ListGroupItem tag="a" href={data.tumblr}>Log in with Tumblr</ListGroupItem>
|
<ListGroupItem tag="a" href={data.discord}>Log in with Discord</ListGroupItem>
|
||||||
<ListGroupItem tag="a" href={data.google}>Log in with Google</ListGroupItem>
|
{/if}
|
||||||
|
{#if data.tumblr}
|
||||||
|
<ListGroupItem tag="a" href={data.tumblr}>Log in with Tumblr</ListGroupItem>
|
||||||
|
{/if}
|
||||||
|
{#if data.google}
|
||||||
|
<ListGroupItem tag="a" href={data.google}>Log in with Google</ListGroupItem>
|
||||||
|
{/if}
|
||||||
</ListGroup>
|
</ListGroup>
|
||||||
<Modal header="Pick an instance" isOpen={modalOpen} toggle={toggleModal}>
|
<Modal header="Pick an instance" isOpen={modalOpen} toggle={toggleModal}>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
|
|
|
@ -132,72 +132,78 @@
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
<div class="my-2">
|
{#if data.user.discord || data.urls.discord}
|
||||||
<Card>
|
<div class="my-2">
|
||||||
<CardBody>
|
<Card>
|
||||||
<CardTitle>Discord</CardTitle>
|
<CardBody>
|
||||||
<CardText>
|
<CardTitle>Discord</CardTitle>
|
||||||
|
<CardText>
|
||||||
|
{#if data.user.discord}
|
||||||
|
Your currently linked Discord account is <b>{data.user.discord_username}</b>
|
||||||
|
(<code>{data.user.discord}</code>).
|
||||||
|
{:else}
|
||||||
|
You do not have a linked Discord account.
|
||||||
|
{/if}
|
||||||
|
</CardText>
|
||||||
{#if data.user.discord}
|
{#if data.user.discord}
|
||||||
Your currently linked Discord account is <b>{data.user.discord_username}</b>
|
<Button color="danger" disabled={!canUnlink} on:click={toggleDiscordUnlinkModal}
|
||||||
(<code>{data.user.discord}</code>).
|
>Unlink account</Button
|
||||||
{:else}
|
>
|
||||||
You do not have a linked Discord account.
|
{:else if data.urls.discord}
|
||||||
|
<Button color="secondary" href={data.urls.discord}>Link account</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</CardText>
|
</CardBody>
|
||||||
{#if data.user.discord}
|
</Card>
|
||||||
<Button color="danger" disabled={!canUnlink} on:click={toggleDiscordUnlinkModal}
|
</div>
|
||||||
>Unlink account</Button
|
{/if}
|
||||||
>
|
{#if data.user.tumblr || data.urls.tumblr}
|
||||||
{:else}
|
<div class="my-2">
|
||||||
<Button color="secondary" href={data.urls.discord}>Link account</Button>
|
<Card>
|
||||||
{/if}
|
<CardBody>
|
||||||
</CardBody>
|
<CardTitle>Tumblr</CardTitle>
|
||||||
</Card>
|
<CardText>
|
||||||
</div>
|
{#if data.user.tumblr}
|
||||||
<div class="my-2">
|
Your currently linked Tumblr account is <b>{data.user.tumblr_username}</b>
|
||||||
<Card>
|
(<code>{data.user.tumblr}</code>).
|
||||||
<CardBody>
|
{:else}
|
||||||
<CardTitle>Tumblr</CardTitle>
|
You do not have a linked Tumblr account.
|
||||||
<CardText>
|
{/if}
|
||||||
|
</CardText>
|
||||||
{#if data.user.tumblr}
|
{#if data.user.tumblr}
|
||||||
Your currently linked Tumblr account is <b>{data.user.tumblr_username}</b>
|
<Button color="danger" disabled={!canUnlink} on:click={toggleTumblrUnlinkModal}
|
||||||
(<code>{data.user.tumblr}</code>).
|
>Unlink account</Button
|
||||||
{:else}
|
>
|
||||||
You do not have a linked Tumblr account.
|
{:else if data.urls.tumblr}
|
||||||
|
<Button color="secondary" href={data.urls.tumblr}>Link account</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</CardText>
|
</CardBody>
|
||||||
{#if data.user.tumblr}
|
</Card>
|
||||||
<Button color="danger" disabled={!canUnlink} on:click={toggleTumblrUnlinkModal}
|
</div>
|
||||||
>Unlink account</Button
|
{/if}
|
||||||
>
|
{#if data.user.google || data.urls.google}
|
||||||
{:else}
|
<div class="my-2">
|
||||||
<Button color="secondary" href={data.urls.tumblr}>Link account</Button>
|
<Card>
|
||||||
{/if}
|
<CardBody>
|
||||||
</CardBody>
|
<CardTitle>Google</CardTitle>
|
||||||
</Card>
|
<CardText>
|
||||||
</div>
|
{#if data.user.google}
|
||||||
<div class="my-2">
|
Your currently linked Google account is <b>{data.user.google_username}</b>
|
||||||
<Card>
|
(<code>{data.user.google}</code>).
|
||||||
<CardBody>
|
{:else}
|
||||||
<CardTitle>Google</CardTitle>
|
You do not have a linked Google account.
|
||||||
<CardText>
|
{/if}
|
||||||
|
</CardText>
|
||||||
{#if data.user.google}
|
{#if data.user.google}
|
||||||
Your currently linked Google account is <b>{data.user.google_username}</b>
|
<Button color="danger" disabled={!canUnlink} on:click={toggleGoogleUnlinkModal}
|
||||||
(<code>{data.user.google}</code>).
|
>Unlink account</Button
|
||||||
{:else}
|
>
|
||||||
You do not have a linked Google account.
|
{:else if data.urls.google}
|
||||||
|
<Button color="secondary" href={data.urls.google}>Link account</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</CardText>
|
</CardBody>
|
||||||
{#if data.user.google}
|
</Card>
|
||||||
<Button color="danger" disabled={!canUnlink} on:click={toggleGoogleUnlinkModal}
|
</div>
|
||||||
>Unlink account</Button
|
{/if}
|
||||||
>
|
|
||||||
{:else}
|
|
||||||
<Button color="secondary" href={data.urls.google}>Link account</Button>
|
|
||||||
{/if}
|
|
||||||
</CardBody>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
<Modal header="Pick an instance" isOpen={fediLinkModalOpen} toggle={toggleFediLinkModal}>
|
<Modal header="Pick an instance" isOpen={fediLinkModalOpen} toggle={toggleFediLinkModal}>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Input placeholder="Instance (e.g. mastodon.social)" bind:value={instance} />
|
<Input placeholder="Instance (e.g. mastodon.social)" bind:value={instance} />
|
||||||
|
|
Loading…
Reference in a new issue