Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

google login nestjs + react-native

$
0
0

I made google login possible using nestjs.

However, I am having a hard time applying this part to react.

  @Get('google')  @UseGuards(GoogleAuthGuard)  async google(@Req() req) {}  @Get('google/callback')  @UseGuards(GoogleAuthGuard)  googleAuthRedirect(@Req() req) {    return this.loginService.googleLogin(req);  }
 async googleLogin(req) {  const { id, refreshToken, accessToken, name, picture, email } = req.user;  ... create jwt ...  return jwt }
export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {  constructor() {    super({      clientID: process.env.GOOGLE_CLIENT_ID, // 1      clientSecret: process.env.GOOGLE_SECRET,      callbackURL: `/auth/google/callback`,      scope: ['email', 'profile'],    });  }  async validate(    accessToken: string,    refreshToken: string,    profile: any,    done: VerifyCallback,  ): Promise<any> {    const { id, name, emails, photos } = profile;    const user = {      email: emails[0].value,      name: name,      picture: photos[0].value,      accessToken,      id,    };    done(null, user);  }

React-native app

InAppBrowser.open('localhost:3000/google', '', {}).then(result => {    console.log(result); InAppBrowser.close();   }});

I wrote the code as above. And jwt is normally created and returned.

The result of running this in a ReactNative app.The login window opened and I was able to log in and get jwt.

However, the callback window is not closed and the token is exposed as is. How can I make it work like a normal login in a reactnative app?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>