我想知道您是否可以帮助解决以下问题,我试图将Google身份验证添加到我的nest.js项目中,这是我在控制器中的代码:
@Get()
@UseGuards(AuthGuard('google'))
async googleAuth(@Req() req) {}
和我的google.strategy.ts:
import { config } from 'dotenv'
import {
Strategy,
VerifyCallback,
} from 'passport-google-oauth20'
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { PassportStrategy } from '@nestjs/passport'
config()
@Injectable()
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
constructor(private configService: ConfigService) {
super({
clientID: configService.get<string>('google.client'), //process.env.GOOGLE_CLIENT_ID,
clientSecret: configService.get<string>('google.secret'), //process.env.GOOGLE_SECRET,
callbackURL: configService.get<string>('google.callback'), //process.env.GOOGLE_CALLBACKURL,
scope: ['email', 'profile'],
})
}
async validate(accessToken: string, refreshToken: string, profile: any, done: VerifyCallback): Promise<any> {
const { name, emails, photos } = profile
const user = {
email: emails[0].value,
firstName: name.givenName,
lastName: name.familyName,
picture: photos[0].value,
// accessToken,
}
done(null, user)
}
}
我收到以下答复:
{"data":"res.setHeader is not a function"}
提前谢谢