user.entity.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { DeepPartial } from '@vendure/common/lib/shared-types';
  2. import { Column, Entity, JoinTable, ManyToMany } from 'typeorm';
  3. import { SoftDeletable } from '../../common/types/common-types';
  4. import { HasCustomFields } from '../../config/custom-field/custom-field-types';
  5. import { VendureEntity } from '../base/base.entity';
  6. import { CustomUserFields } from '../custom-entity-fields';
  7. import { Role } from '../role/role.entity';
  8. /**
  9. * @description
  10. * A User represents any authenticated user of the Vendure API. This includes both
  11. * {@link Administrator}s as well as registered {@link Customer}s.
  12. *
  13. * @docsCategory entities
  14. */
  15. @Entity()
  16. export class User extends VendureEntity implements HasCustomFields, SoftDeletable {
  17. constructor(input?: DeepPartial<User>) {
  18. super(input);
  19. }
  20. @Column({ type: Date, nullable: true })
  21. deletedAt: Date | null;
  22. @Column()
  23. identifier: string;
  24. @Column({ select: false }) passwordHash: string;
  25. @Column({ default: false })
  26. verified: boolean;
  27. @Column({ type: 'varchar', nullable: true })
  28. verificationToken: string | null;
  29. @Column({ type: 'varchar', nullable: true })
  30. passwordResetToken: string | null;
  31. /**
  32. * @description
  33. * A token issued when a User requests to change their identifier (typically
  34. * an email address)
  35. */
  36. @Column({ type: 'varchar', nullable: true })
  37. identifierChangeToken: string | null;
  38. /**
  39. * @description
  40. * When a request has been made to change the User's identifier, the new identifier
  41. * will be stored here until it has been verified, after which it will
  42. * replace the current value of the `identifier` field.
  43. */
  44. @Column({ type: 'varchar', nullable: true })
  45. pendingIdentifier: string | null;
  46. @ManyToMany(type => Role)
  47. @JoinTable()
  48. roles: Role[];
  49. @Column({ nullable: true })
  50. lastLogin: string;
  51. @Column(type => CustomUserFields)
  52. customFields: CustomUserFields;
  53. }