import UserModel from "../entities/User" ; interface IUpsertUser { socialId : string ; email : string ; avatarUrl : string ; username : string ; displayName : string ; } const UpsertUser = async ( provider , { socialId , email , username , displayName , avatarUrl } , done ) => { const userData = { avatarUrl : avatarUrl , provider : provider , socialId : socialId , username : username , email : email , name : displayName , } ; try { const matchedUser = await UserModel . findOne ( { email : userData . email } ) ; if ( matchedUser ) { return done ( null , matchedUser ) ; } const newUser = new UserModel ( userData ) ; await newUser . save ( ) ; return done ( null , newUser ) ; } catch ( err ) { return done ( err , null ) ; } } ; export default UpsertUser ;