import { createHash } from 'crypto'; import JSEncrypt from 'jsencrypt'; import { LocalScheme } from '~auth/runtime'; // const { createHash } = await import('node:crypto'); let publicKey; const encrypt = new JSEncrypt(); export default class CustomScheme extends LocalScheme { async login(endpoint, { reset = true } = {}) { endpoint.data = Object.assign({}, endpoint.data); if (!this.options.endpoints.login) { return; } if (reset) { this.$auth.reset({ resetInterceptor: false }); } if (this.options.clientId) { endpoint.data.client_id = this.options.clientId; } if (this.options.grantType) { endpoint.data.grant_type = this.options.grantType; } if (this.options.scope) { endpoint.data.scope = this.options.scope; } if (!publicKey) { publicKey = ( await this.$auth.ctx.$axios.$post('/user/v1/client/login/getPbKey') ).data.publicKey; encrypt.setPublicKey(publicKey); } console.log( '🚀 ~ file: password.js ~ line 37 ~ CustomScheme ~ login ~ publicKey', publicKey, ); const md5 = createHash('md5'); endpoint.data.password = encrypt.encrypt( md5.update(endpoint.data.password, 'utf-8').digest('hex'), ); // privateEncrypt(publicKey, endpoint.data.md5).toString('base64'); // endpoint.data.uuid = '132514568481654'; endpoint.data.client = 7; const response = await this.$auth.request( endpoint, this.options.endpoints.login, ); this.updateTokens(response); if (!this.requestHandler.interceptor) { this.initializeRequestInterceptor(); } if (this.options.user.autoFetch) { await this.fetchUser(); } return response; } }