user.entity.ts 1.8 KB

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