How to use the apollo-server-errors.AuthenticationError function in apollo-server-errors

To help you get started, we’ve selected a few apollo-server-errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / merchant-center-application-kit / packages / application-shell / src / components / application-shell / application-shell.spec.js View on Github external
beforeEach(() => {
    createGraphqlMockServer(xhrMock, {
      operationsByTarget: {
        mc: mocksForMc.createMockOperations({
          FetchLoggedInUser: {
            me: new AuthenticationError('User is not authorized'),
          },
        }),
      },
    });
  });
  it('should redirect to "/logout" with reason unauthorized', async () => {
github sysgears / apollo-universal-starter-kit / modules / authentication / server-ts / access / jwt / resolvers.js View on Github external
if (!isValidToken) {
        throw new AuthenticationError(t('auth:invalidRefresh'));
      }

      if (!getIdentity) {
        throw new AuthenticationError(t('auth:getIdentify'));
      }

      const identity = await getIdentity(decodedToken.id);
      const hash = getHash ? await getHash(decodedToken.id) : '';
      const refreshSecret = settings.auth.secret + hash;

      try {
        jwt.verify(inputRefreshToken, refreshSecret);
      } catch (e) {
        throw new AuthenticationError(e);
      }

      const [accessToken, refreshToken] = await createTokens(identity, settings.auth.secret, refreshSecret);

      return {
        accessToken,
        refreshToken
      };
    }
  }
github sysgears / apollo-universal-starter-kit / modules / authentication / server-ts / access / jwt / createTokens.js View on Github external
const createTokens = async (identity, secret, refreshSecret, t) => {
  if (!identity.id) {
    throw new AuthenticationError(t('auth:identityWithoutId'));
  }

  const createToken = jwt.sign({ identity }, secret, { expiresIn: tokenExpiresIn });
  const createRefreshToken = jwt.sign({ id: identity.id }, refreshSecret, { expiresIn: refreshTokenExpiresIn });

  return Promise.all([createToken, createRefreshToken]);
};
github sysgears / apollo-universal-starter-kit / modules / authentication / server-ts / access / jwt / resolvers.js View on Github external
{ refreshToken: inputRefreshToken },
      {
        getIdentity,
        getHash,
        req: { t }
      }
    ) {
      const decodedToken = jwt.decode(inputRefreshToken);
      const isValidToken = decodedToken && decodedToken.id;

      if (!isValidToken) {
        throw new AuthenticationError(t('auth:invalidRefresh'));
      }

      if (!getIdentity) {
        throw new AuthenticationError(t('auth:getIdentify'));
      }

      const identity = await getIdentity(decodedToken.id);
      const hash = getHash ? await getHash(decodedToken.id) : '';
      const refreshSecret = settings.auth.secret + hash;

      try {
        jwt.verify(inputRefreshToken, refreshSecret);
      } catch (e) {
        throw new AuthenticationError(e);
      }

      const [accessToken, refreshToken] = await createTokens(identity, settings.auth.secret, refreshSecret);

      return {
        accessToken,
github sysgears / apollo-universal-starter-kit / modules / authentication / server-ts / access / jwt / index.js View on Github external
const createContextFunc = async ({ req }) => {
  try {
    if (req) {
      req.identity = req.identity || (await getCurrentIdentity({ req }));
    }
  } catch (e) {
    throw new AuthenticationError(e);
  }
};