mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 11:54:10 +00:00 
			
		
		
		
	Use a custom findOneByEmail to search for existing user
This commit is contained in:
		
							parent
							
								
									08d27c0ea5
								
							
						
					
					
						commit
						fdefb1382c
					
				@ -27,7 +27,7 @@ const authenticate = async (ctx, next) => {
 | 
			
		||||
      return ctx.redirect(redirectUrls.error);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const user = await getService('user').findOne({ email: profile.email });
 | 
			
		||||
    const user = await getService('user').findOneByEmail(profile.email);
 | 
			
		||||
    const scenario = user ? existingUserScenario : nonExistingUserScenario;
 | 
			
		||||
 | 
			
		||||
    return scenario(ctx, next)(user || profile, provider);
 | 
			
		||||
 | 
			
		||||
@ -180,6 +180,19 @@ const findOne = async (id, populate = ['roles']) => {
 | 
			
		||||
  return strapi.entityService.findOne('admin::user', id, { populate });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Find one user by its email
 | 
			
		||||
 * @param {string} id  email
 | 
			
		||||
 * @param {string || string[] || object} populate
 | 
			
		||||
 * @returns
 | 
			
		||||
 */
 | 
			
		||||
const findOneByEmail = async (email, populate = []) => {
 | 
			
		||||
  return strapi.query('admin::user').findOne({
 | 
			
		||||
    where: { email },
 | 
			
		||||
    populate,
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/** Find many users (paginated)
 | 
			
		||||
 * @param query
 | 
			
		||||
 * @returns {Promise<user>}
 | 
			
		||||
@ -309,6 +322,7 @@ module.exports = {
 | 
			
		||||
  register,
 | 
			
		||||
  sanitizeUser,
 | 
			
		||||
  findOne,
 | 
			
		||||
  findOneByEmail,
 | 
			
		||||
  findPage,
 | 
			
		||||
  deleteById,
 | 
			
		||||
  deleteByIds,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user