Skip to content

Instantly share code, notes, and snippets.

@sofyan-ahmad
Created May 27, 2020 03:46
Show Gist options
  • Save sofyan-ahmad/b6b1355c5aba6714b009d55a29647705 to your computer and use it in GitHub Desktop.
Save sofyan-ahmad/b6b1355c5aba6714b009d55a29647705 to your computer and use it in GitHub Desktop.
import {Body, Controller, Get, Post, Render} from '@nestjs/common';
import {GoogleApiService} from './googleApi.service';
@Controller()
export class GoogleApiController {
constructor(private readonly service: GoogleApiService) {}
@Get('authorize')
@Render('main')
authorize(): {message: string; link: string; view: string} {
return {...this.service.generateNewAuthUrl(), view: 'authorize'};
}
@Post('authorize')
async setAuthorizationCode(@Body() body: {code: string}): Promise<string> {
await this.service.setNewToken(body.code);
return 'Google authorization code saved';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment