piglovesyou / nextjs-passport-oauth-example

5 stars 0 forks source link

How to use identifyUser with now/node API? #5

Closed itsdarrylnorris closed 4 years ago

itsdarrylnorris commented 4 years ago

Problem

I am trying to figure out how I can use the identifyUser function on now/node API. I tried to call the function inside of simple API and I am getting some errors.

/api/user.ts

import { NowRequest, NowResponse } from '@now/node'
import { identifyUser } from '../lib/auth/withIdentity'

export default async function(req: NowRequest, res: NowResponse) {
  const user = await identifyUser({ req, res })

  if (req)
    res.status(200).json({
      status: 'ok',
      user: user,
    })
}

And I am getting this error:

/private/var/folders/lc/4j_lrdk555vg_m9nh5b7f8lm0000gn/T/zeit-fun-ebb0b78e25cb4/lib/auth/withIdentity.js:67
                <IdentityContext.Provider value={user}>
                ^

SyntaxError: Unexpected token '<'
    at wrapSafe (internal/modules/cjs/loader.js:1060:16)
    at Module._compile (internal/modules/cjs/loader.js:1108:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
    at Module.load (internal/modules/cjs/loader.js:993:32)
    at Function.Module._load (internal/modules/cjs/loader.js:892:14)
    at Module.require (internal/modules/cjs/loader.js:1033:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Project/api/user.ts:2:1)
    at Module._compile (internal/modules/cjs/loader.js:1144:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
LambdaError: RequestId: 26eee61b-c84f-41b4-9adf-63af41285725 Process exited before completing request
    at Lambda.<anonymous> (/Users/darrylnorris/.yarn-global/node_modules/now/dist/index.js:2:3545506)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/darrylnorris/.yarn-global/node_modules/now/dist/index.js:2:3543393)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
piglovesyou commented 4 years ago
const [reqProxy] = composePassport.initializePassport(req, res);
reqProxy.user; // <-

I also recommend you to understand how Passport works first.

itsdarrylnorris commented 4 years ago

I thought this is a Next.js example and it doesn't have perfect compatibility to @now/node

If you think the issue is out-scope from this project. We can close it.

This ↓ might be what you want, but I didn't validate it.

Thanks, I could play around with this later today.

itsdarrylnorris commented 4 years ago

Hey @piglovesyou ,

I tried this in identifyUser() and does not seems to be working.

const [reqProxy] = composePassport.initializePassport(req, res);
reqProxy.user; // <-

I am going to close this task since is out the scope of this project. Also, I can keep track of my own session after the user login.