1

I am in trouble with the serverless-offline plugin:

When my serverless is deployed to aws cookies works fine,

But it's doesn't work on localhost with plugin.

I saw somewhere than it's will perhaps be possible to make it works with a custom velocity template, but idk how to do it.

We are using lambda integration

this is my serverless.yml to set the cookie:

  login:
    handler: functions/auth/login.handler
    events:
      - http:
          path: login
          method: post
          cors: true
          integration: lambda
          response:
            headers:
              Set-Cookie: integration.response.body.body
            statusCodes:
              200:
                pattern: '' # Default response method
              400:
                pattern: '.*"statusCode": 400,.*'
                template: $input.path("$.errorMessage")
              401:
                pattern: '.*"statusCode": 401,.*'
                template: $input.path("$.errorMessage")
              500:
                pattern: '.*"statusCode": 500,.*'
                template: $input.path("$.errorMessage")

here is the code of my lambda function where I set my cookie:

import { ok, internalServerError, unAuthorized } from '../../lib/response.js';
import { login } from '../../lib/token.js';
import { logger } from '../../lib/logger.js';
import { authLambda } from '../../constants/constant.js';

export const handler = async (event) => {
  logger.info('START', authLambda.login);

  let responseObject;
  let date = new Date();
  date.setTime(+ date + (86400000)); // 24h

  try {
    const token = await login(event.body);

    if (token) {
      let cookie = 'auth='+token
      responseObject = ok(cookie);
    } else {
      responseObject = unAuthorized();
    }
        
    logger.info('END => ', authLambda.login, responseObject);

    return responseObject;
  } catch (e) {
    logger.error('ERROR', authLambda.login, e);
    return new Error(internalServerError(e));
  }
};
17J4CK
  • 11
  • 5

0 Answers0