node.js - How to partially save an entity's properties to different database? - Stack Overflow

BackgroundI'm implementing an API endpoint for creating a user with MikroORM. Requirement tells m

Background

I'm implementing an API endpoint for creating a user with MikroORM. Requirement tells me that I need the user info saved on a PostgreSQL server—except for user password; I need the passwords stored on the Firebase Authentication backend for some reason.

Wanted Behavior

I'm trying to get the following to work.

const newUser = new User({
  email: '[email protected]',
  password: 'mypassword'
});

em.persist(newUser).flush(); // save email to Postgres, save password to Firebase

My failed attempt at the solution

I'm trying to lean on MikroORM's Virtual Properties feature.

@Entity()
class User {
    /** -- snipped -- */

    @Property({ type: 'varchar', length: 50 })
    email!: number;

    @Property({ persist: false })
    set password(value: string) {
        setPasswordOnFirebase(this, value); // password gets saved before persist and flush
                                            // how to even handle async saving and errors?
    }
}

Questions

Is it possible in MikroORM to accomplish the wanted behavior I have in mind? Or should I simply create a separate endpoint for custom storing of password?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745247781a4618492.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信