Skip to content

Commit

Permalink
Fix user profile fetch for local user
Browse files Browse the repository at this point in the history
  • Loading branch information
paustint committed Feb 9, 2024
1 parent b098867 commit 958e2a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/app/controllers/sf-query.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NextFunction, Request, Response } from 'express';
import { body, query as queryString } from 'express-validator';
import * as jsforce from 'jsforce';
import * as queryService from '../services/query';
import { sendJson } from '../utils/response.handlers';
import { UserFacingError } from '../utils/error-handler';
import { body, query as queryString } from 'express-validator';
import { sendJson } from '../utils/response.handlers';

export const routeValidators = {
query: [body('query').isString()],
Expand Down
9 changes: 8 additions & 1 deletion apps/api/src/app/controllers/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger, mailgun } from '@jetstream/api-config';
import { ENV, logger, mailgun } from '@jetstream/api-config';
import { UserProfileAuth0Ui, UserProfileServer, UserProfileUi, UserProfileUiWithIdentities } from '@jetstream/types';
import { AxiosError } from 'axios';
import * as express from 'express';
Expand Down Expand Up @@ -60,6 +60,13 @@ export async function emailSupport(req: express.Request, res: express.Response)

export async function getUserProfile(req: express.Request, res: express.Response) {
const auth0User = req.user as UserProfileServer;

// use fallback locally and on CI
if (ENV.EXAMPLE_USER_OVERRIDE && ENV.EXAMPLE_USER_PROFILE && req.hostname === 'localhost') {
sendJson(res, ENV.EXAMPLE_USER_PROFILE);
return;
}

const user = await userDbService.findByUserId(auth0User.id);
if (!user) {
throw new UserFacingError('User not found');
Expand Down
12 changes: 11 additions & 1 deletion libs/api-config/src/lib/env-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ensureBoolean, ensureStringValue } from '@jetstream/shared/utils';
import { UserProfileServer } from '@jetstream/types';
import { UserProfileServer, UserProfileUi } from '@jetstream/types';
import * as dotenv from 'dotenv';
import { readFileSync } from 'fs-extra';
import { join } from 'path';
Expand Down Expand Up @@ -41,11 +41,21 @@ const EXAMPLE_USER: UserProfileServer = {
user_id: 'EXAMPLE_USER',
};

const EXAMPLE_USER_PROFILE: UserProfileUi = {
...EXAMPLE_USER._json,
id: 'EXAMPLE_USER',
userId: 'EXAMPLE_USER',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
preferences: { skipFrontdoorLogin: false },
};

export const ENV = {
IS_CI: ensureBoolean(process.env.CI),
// LOCAL OVERRIDE
EXAMPLE_USER_OVERRIDE: ensureBoolean(process.env.EXAMPLE_USER_OVERRIDE),
EXAMPLE_USER: process.env.EXAMPLE_USER_OVERRIDE ? EXAMPLE_USER : null,
EXAMPLE_USER_PROFILE: process.env.EXAMPLE_USER_OVERRIDE ? EXAMPLE_USER_PROFILE : null,
// SYSTEM
NODE_ENV: process.env.NODE_ENV,
ENVIRONMENT: process.env.ENVIRONMENT || 'production',
Expand Down

0 comments on commit 958e2a7

Please sign in to comment.