mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-03 14:19:56 +00:00
parent
36bc394e7a
commit
3e64ec0f07
@ -1,7 +1,10 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { concatLink } from '@hcengineering/core'
|
||||||
|
import { getMetadata } from '@hcengineering/platform'
|
||||||
import { AnySvelteComponent, Button, Grid, getCurrentLocation } from '@hcengineering/ui'
|
import { AnySvelteComponent, Button, Grid, getCurrentLocation } from '@hcengineering/ui'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { getProviders, loginWithProvider } from '../utils'
|
import login from '../plugin'
|
||||||
|
import { getProviders } from '../utils'
|
||||||
import Github from './providers/Github.svelte'
|
import Github from './providers/Github.svelte'
|
||||||
import Google from './providers/Google.svelte'
|
import Google from './providers/Google.svelte'
|
||||||
|
|
||||||
@ -34,22 +37,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const location = getCurrentLocation()
|
const location = getCurrentLocation()
|
||||||
|
|
||||||
|
function getLink (provider: Provider): string {
|
||||||
|
const inviteId = location.query?.inviteId
|
||||||
|
const accountsUrl = getMetadata(login.metadata.AccountsUrl) ?? ''
|
||||||
|
let path = `/auth/${provider.name}`
|
||||||
|
if (inviteId != null) {
|
||||||
|
path += `?inviteId=${inviteId}`
|
||||||
|
}
|
||||||
|
return concatLink(accountsUrl, path)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<Grid column={getColumnsCount(enabledProviders.length)} columnGap={1} rowGap={1} alignItems={'center'}>
|
<Grid column={getColumnsCount(enabledProviders.length)} columnGap={1} rowGap={1} alignItems={'center'}>
|
||||||
{#each enabledProviders as provider}
|
{#each enabledProviders as provider}
|
||||||
<Button
|
<a href={getLink(provider)} target="_blank" rel="noopener noreferrer">
|
||||||
kind={'contrast'}
|
<Button kind={'contrast'} shape={'round2'} size={'x-large'} width="100%" stopPropagation={false}>
|
||||||
shape={'round2'}
|
<svelte:fragment slot="content">
|
||||||
size={'x-large'}
|
<svelte:component this={provider.component} />
|
||||||
width="100%"
|
</svelte:fragment>
|
||||||
on:click={() => loginWithProvider(provider.name, location.query?.inviteId)}
|
</Button>
|
||||||
>
|
</a>
|
||||||
<svelte:fragment slot="content">
|
|
||||||
<svelte:component this={provider.component} />
|
|
||||||
</svelte:fragment>
|
|
||||||
</Button>
|
|
||||||
{/each}
|
{/each}
|
||||||
</Grid>
|
</Grid>
|
||||||
</div>
|
</div>
|
||||||
|
@ -887,26 +887,3 @@ export async function getProviders (): Promise<string[]> {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loginWithProvider (provider: string, inviteId?: string | null): Promise<void> {
|
|
||||||
const accountsUrl = getMetadata(login.metadata.AccountsUrl)
|
|
||||||
|
|
||||||
if (accountsUrl === undefined) {
|
|
||||||
throw new Error('accounts url not specified')
|
|
||||||
}
|
|
||||||
|
|
||||||
let path = `/auth/${provider}`
|
|
||||||
|
|
||||||
if (inviteId != null) {
|
|
||||||
path += `?inviteId=${inviteId}`
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(concatLink(accountsUrl, path))
|
|
||||||
Analytics.handleEvent(`Login with ${provider}`)
|
|
||||||
const result = await response.json()
|
|
||||||
return result
|
|
||||||
} catch (err: any) {
|
|
||||||
Analytics.handleError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user