mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Prevent deactivated user to connect using sso
This commit is contained in:
parent
9f01afca88
commit
e9b9013e4a
@ -26,15 +26,31 @@ const authenticate = async (ctx, next) => {
|
|||||||
return ctx.redirect(redirectUrls.error);
|
return ctx.redirect(redirectUrls.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { email, firstname, lastname, username } = profile;
|
const user = await strapi.admin.services.user.findOne({ email: profile.email });
|
||||||
const user = await strapi.admin.services.user.findOne({ email });
|
const scenario = user ? existingUserScenario : nonExistingUserScenario;
|
||||||
|
|
||||||
// If a profile exists with this email, login with this user
|
return scenario(ctx, next)(user || profile, provider);
|
||||||
if (user) {
|
})(ctx, next);
|
||||||
ctx.state.user = user;
|
};
|
||||||
return next();
|
|
||||||
|
const existingUserScenario = (ctx, next) => async (user, provider) => {
|
||||||
|
const redirectUrls = utils.getPrefixedRedirectUrls();
|
||||||
|
|
||||||
|
if (!user.isActive) {
|
||||||
|
strapi.eventHub.emit('admin.auth.error', {
|
||||||
|
error: new Error(`Deactivated user tried to login (${user.id})`),
|
||||||
|
provider,
|
||||||
|
});
|
||||||
|
return ctx.redirect(redirectUrls.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.state.user = user;
|
||||||
|
return next();
|
||||||
|
};
|
||||||
|
|
||||||
|
const nonExistingUserScenario = (ctx, next) => async (profile, provider) => {
|
||||||
|
const { email, firstname, lastname, username } = profile;
|
||||||
|
const redirectUrls = utils.getPrefixedRedirectUrls();
|
||||||
const adminStore = await utils.getAdminStore();
|
const adminStore = await utils.getAdminStore();
|
||||||
const { providers } = await adminStore.get({ key: 'auth' });
|
const { providers } = await adminStore.get({ key: 'auth' });
|
||||||
|
|
||||||
@ -71,7 +87,6 @@ const authenticate = async (ctx, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
})(ctx, next);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const redirectWithAuth = ctx => {
|
const redirectWithAuth = ctx => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user