How to integrate routing for google authentication?

Hey @ShehabSN :wave:

It’s not obvious, but you can add your own route handlers in the src/api/functions directory. Here’s a quick example I whipped-up:

// src/api/functions/random.js

export const handler = (event, context, cb) => {
  console.log(event, context)
  cb({ hello: 'world' })
}

After starting up Redwood (yarn rw dev) you can visit http://localhost:8911/random and this will get printed to the page:

{ "hello": "world" }

On the command-line, you’ll see the following output. I just did this to help you see what kind of data is passed in via the event and context arguments:

11:23:24 api | {
11:23:24 api |   httpMethod: 'GET',
11:23:24 api |   headers: {
11:23:24 api |     host: 'localhost:8911',
11:23:24 api |     connection: 'keep-alive',
11:23:24 api |     pragma: 'no-cache',
11:23:24 api |     'cache-control': 'no-cache',
11:23:24 api |     'upgrade-insecure-requests': '1',
11:23:24 api |     'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
11:23:24 api |     'sec-fetch-dest': 'document',
11:23:24 api |     accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
11:23:24 api |     'sec-fetch-site': 'none',
11:23:24 api |     'sec-fetch-mode': 'navigate',
11:23:24 api |     'sec-fetch-user': '?1',
11:23:24 api |     'accept-encoding': 'gzip, deflate, br',
11:23:24 api |     'accept-language': 'en-US,en;q=0.9',
11:23:24 api |     cookie: '_ga=GA1.1.1241974949.1584989253'
11:23:24 api |   },
11:23:24 api |   path: '/random',
11:23:24 api |   queryStringParameters: {},
11:23:24 api |   body: '',
11:23:24 api |   isBase64Encoded: false
11:23:24 api | } {}

I hope this helps!

1 Like