Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const CLS_NAME = 'OauthService';
@Injectable()
export class OauthService {
constructor(
@InjectRepository(User) private readonly userRepository: Repository,
@InjectRepository(Oauth) private readonly oauthRepository: Repository,
) {}
// prettier-ignore
// eslint-disable-next-line max-len
private checkMiniProgramConfig = () => oauthConfig.wechat.miniProgram && oauthConfig.wechat.miniProgram.appId && oauthConfig.wechat.miniProgram.appSecret;
private checkWechatConfig = () => oauthConfig.wechat.appId && oauthConfig.wechat.appSecret;
private wechat = this.checkWechatConfig() && new Wechat(oauthConfig.wechat);
private wechatOAuth = this.checkWechatConfig() && new OAuth(oauthConfig.wechat);
private miniProgram = this.checkMiniProgramConfig() && new MiniProgram(oauthConfig.wechat);
async bindUserIdToOauth(user: User, oid: number): Promise {
if (!oid || typeof Number(oid) !== 'number') return errorUtil.ERROR({ error: `Nout Found oid ${oid}`, user });
const oauth = await this.oauthRepository.findOne({ id: Number(oid) });
if (!oauth) return errorUtil.ERROR({ error: `Not Found Oauth ${oid}`, user });
const result = await this.oauthRepository.update(Number(oid), { user_id: user.id });
if (!result) return errorUtil.ERROR({ error: `Binding ${oid} Failed`, user });
return result;
}
async clearTicket(oauthId: number): Promise {
@Injectable()
export class OauthService {
constructor(
@InjectRepository(User) private readonly userRepository: Repository,
@InjectRepository(Oauth) private readonly oauthRepository: Repository,
) {}
// prettier-ignore
// eslint-disable-next-line max-len
private checkMiniProgramConfig = () => oauthConfig.wechat.miniProgram && oauthConfig.wechat.miniProgram.appId && oauthConfig.wechat.miniProgram.appSecret;
private checkWechatConfig = () => oauthConfig.wechat.appId && oauthConfig.wechat.appSecret;
private wechat = this.checkWechatConfig() && new Wechat(oauthConfig.wechat);
private wechatOAuth = this.checkWechatConfig() && new OAuth(oauthConfig.wechat);
private miniProgram = this.checkMiniProgramConfig() && new MiniProgram(oauthConfig.wechat);
async bindUserIdToOauth(user: User, oid: number): Promise {
if (!oid || typeof Number(oid) !== 'number') return errorUtil.ERROR({ error: `Nout Found oid ${oid}`, user });
const oauth = await this.oauthRepository.findOne({ id: Number(oid) });
if (!oauth) return errorUtil.ERROR({ error: `Not Found Oauth ${oid}`, user });
const result = await this.oauthRepository.update(Number(oid), { user_id: user.id });
if (!result) return errorUtil.ERROR({ error: `Binding ${oid} Failed`, user });
return result;
}
async clearTicket(oauthId: number): Promise {
await this.oauthRepository.update(oauthId, { ticket: '', ticket_at: '' });
}
const CLS_NAME = 'OauthService';
@Injectable()
export class OauthService {
constructor(
@InjectRepository(User) private readonly userRepository: Repository,
@InjectRepository(Oauth) private readonly oauthRepository: Repository,
) {}
// prettier-ignore
// eslint-disable-next-line max-len
private checkMiniProgramConfig = () => oauthConfig.wechat.miniProgram && oauthConfig.wechat.miniProgram.appId && oauthConfig.wechat.miniProgram.appSecret;
private checkWechatConfig = () => oauthConfig.wechat.appId && oauthConfig.wechat.appSecret;
private wechat = this.checkWechatConfig() && new Wechat(oauthConfig.wechat);
private wechatOAuth = this.checkWechatConfig() && new OAuth(oauthConfig.wechat);
private miniProgram = this.checkMiniProgramConfig() && new MiniProgram(oauthConfig.wechat);
async bindUserIdToOauth(user: User, oid: number): Promise {
if (!oid || typeof Number(oid) !== 'number') return errorUtil.ERROR({ error: `Nout Found oid ${oid}`, user });
const oauth = await this.oauthRepository.findOne({ id: Number(oid) });
if (!oauth) return errorUtil.ERROR({ error: `Not Found Oauth ${oid}`, user });
const result = await this.oauthRepository.update(Number(oid), { user_id: user.id });
if (!result) return errorUtil.ERROR({ error: `Binding ${oid} Failed`, user });
return result;
}
async clearTicket(oauthId: number): Promise {
await this.oauthRepository.update(oauthId, { ticket: '', ticket_at: '' });
constructor(
private readonly jwtService: JwtService,
private readonly usersService: UserService,
private readonly cacheService: CacheService,
) {
this.wx = new Wechat(this.wechatConfig);
this.mp = this.wx.miniProgram;
}