mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-08-03 19:17:07 -04:00
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { useMainStore } from '../store/index.ts';
|
|
|
|
import { getUrlForLocale } from '~/src/domain.ts';
|
|
|
|
export default () => {
|
|
const store = useMainStore();
|
|
|
|
const buildSocialLoginConnectLink = (
|
|
locale: string,
|
|
provider: string,
|
|
providerOptions: Record<string, any>,
|
|
instance: string | null = null,
|
|
): string => {
|
|
const url = providerOptions.redirectViaHome
|
|
? new URL(`/api/user/social-redirect/${provider}/${locale}`, getUrlForLocale('_'))
|
|
: new URL(`/api/connect/${provider}`, getUrlForLocale(locale));
|
|
|
|
if (providerOptions.instanceRequired && instance) {
|
|
url.searchParams.append('instance', instance ?? '');
|
|
}
|
|
|
|
if (providerOptions.redirectViaHome && store.token) {
|
|
// if a logged in user on a domain that's not *.pronouns.page connects a new oauth account,
|
|
// home domain doesn't have the token (cross-domain cookie) and instead of connecting
|
|
// we create a brand new account. let's just pass the token to it
|
|
url.searchParams.append('token', store.token);
|
|
}
|
|
|
|
return url.toString();
|
|
};
|
|
|
|
return {
|
|
buildSocialLoginConnectLink,
|
|
};
|
|
};
|