0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

fix(console): admin user should be able to link google account to profile (#3297)

This commit is contained in:
Charles Zhao 2023-03-06 16:48:50 +08:00 committed by GitHub
parent ea66dcbf2f
commit 88cb4590ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 12 deletions

View file

@ -12,10 +12,13 @@ const HandleSocialCallback = () => {
useEffect(() => {
(async () => {
const connectorId = sessionStorage.getItem(profileSocialLinkingKeyPrefix);
const connectorData = Object.fromEntries(new URLSearchParams(search));
sessionStorage.removeItem(profileSocialLinkingKeyPrefix);
if (connectorId) {
sessionStorage.removeItem(profileSocialLinkingKeyPrefix);
const queries = new URLSearchParams(search);
queries.set('redirectUri', `${adminTenantEndpoint}/callback/${connectorId}`);
const connectorData = Object.fromEntries(queries);
await api.post('me/social/link-identity', { json: { connectorId, connectorData } });
window.close();

View file

@ -81,12 +81,13 @@ export const createUserQueries = (pool: CommonQueryMethods) => {
${conditionalSql(excludeUserId, (id) => sql`and ${fields.id}<>${id}`)}
`);
const hasUserWithIdentity = async (target: string, userId: string) =>
const hasUserWithIdentity = async (target: string, userId: string, excludeUserId?: string) =>
pool.exists(
sql`
select ${fields.id}
from ${table}
where ${fields.identities}::json#>>'{${sql.identifier([target])},userId}' = ${userId}
${conditionalSql(excludeUserId, (id) => sql`and ${fields.id}<>${id}`)}
`
);

View file

@ -113,14 +113,6 @@ export default function socialRoutes<T extends AuthedMeRouter>(
const { target } = connector.metadata;
assertThat(
!has(user.identities, target),
new RequestError({
code: 'user.social_account_exists_in_profile',
status: 422,
})
);
/**
* Same as above, passing `notImplemented` only works for connectors not relying on session storage.
* E.g. Google and GitHub
@ -131,7 +123,7 @@ export default function socialRoutes<T extends AuthedMeRouter>(
});
assertThat(
!(await hasUserWithIdentity(target, socialUserInfo.id)),
!(await hasUserWithIdentity(target, socialUserInfo.id, userId)),
new RequestError({
code: 'user.identity_already_in_use',
status: 422,