hedgedoc/src/components/login-page/auth/utils.ts
Tilman Vatteroth 5e06e4ab3c fix: don't suppress error when fetching user information
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2022-08-25 14:57:49 +02:00

34 lines
1.1 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { getMe } from '../../../api/me'
import { setUser } from '../../../redux/user/methods'
import type { AuthProvider } from '../../../api/config/types'
import { authProviderTypeOneClick } from '../../../api/config/types'
/**
* Fetches metadata about the currently signed-in user from the API and stores it into the redux.
*/
export const fetchAndSetUser: () => Promise<void> = async () => {
const me = await getMe()
setUser({
username: me.username,
displayName: me.displayName,
photo: me.photo,
authProvider: me.authProvider,
email: me.email
})
}
/**
* Filter to apply to a list of auth providers to get only one-click providers.
*
* @param provider The provider to test whether it is a one-click provider or not.
* @return {@link true} when the provider is a one-click one, {@link false} otherwise.
*/
export const filterOneClickProviders = (provider: AuthProvider): boolean => {
return authProviderTypeOneClick.includes(provider.type)
}