Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ar(feat) [DPTM-11]: Add Sentry to Hypnos; ar(fix): [DPCP-123]: Load Services in First Sign-up #56

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/deploy_gcp_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ jobs:
NEXUS_STANDALONE=true
PRISMA_PRIVATE_URI=${{ secrets.MONGODB_PRIVATE_URI_PROD }}
PRISMA_PUBLIC_URI=${{ secrets.MONGODB_PUBLIC_URI_PROD }}
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN_PROD }}
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN_PROD }}
NEXT_PUBLIC_SENTRY_DSN=${{ secrets.NEXT_PUBLIC_SENTRY_DSN_PROD }}
SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT_PROD }}
SENTRY_ORG=${{ secrets.SENTRY_ORG_PROD }}
VERCEL_GIT_COMMIT_SHA=${{ github.sha }}


- name: hypnos::deploy_prod::docker::Generate artifact attestation
uses: actions/attest-build-provenance@v1
Expand Down
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ ARG MONGODB_PUBLIC_URI
ARG NEXUS_MODE
ARG NEXUS_KEEPALIVE

ARG SENTRY_AUTH_TOKEN
ARG SENTRY_PROJECT
ARG SENTRY_ORG
ARG NEXT_PUBLIC_SENTRY_DSN
ARG VERCEL_GIT_COMMIT_SHA

# ENV FROM ARGS VARS
ENV AUTH_GITHUB_ID=$AUTH_GITHUB_ID
ENV AUTH_GITHUB_SECRET=$AUTH_GITHUB_SECRET
Expand Down Expand Up @@ -120,6 +126,12 @@ ENV MONGODB_PUBLIC_URI=$MONGODB_PUBLIC_URI
ENV NEXUS_MODE=$NEXUS_MODE
ENV NEXUS_KEEPALIVE=$NEXUS_KEEPALIVE

ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
ENV SENTRY_PROJECT=$SENTRY_PROJECT
ENV SENTRY_ORG=$SENTRY_ORG
ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN
ENV VERCEL_GIT_COMMIT_SHA=$VERCEL_GIT_COMMIT_SHA


RUN \
if [ -f yarn.lock ]; then yarn run build:vm; \
Expand Down Expand Up @@ -176,6 +188,12 @@ ARG MONGODB_PUBLIC_URI
ARG NEXUS_MODE
ARG NEXUS_KEEPALIVE

ARG SENTRY_AUTH_TOKEN
ARG SENTRY_PROJECT
ARG SENTRY_ORG
ARG NEXT_PUBLIC_SENTRY_DSN
ARG VERCEL_GIT_COMMIT_SHA

# ENV FROM ARGS VARS
ENV AUTH_GITHUB_ID=$AUTH_GITHUB_ID
ENV AUTH_GITHUB_SECRET=$AUTH_GITHUB_SECRET
Expand Down Expand Up @@ -216,6 +234,12 @@ ENV MONGODB_PUBLIC_URI=$MONGODB_PUBLIC_URI
ENV NEXUS_MODE=$NEXUS_MODE
ENV NEXUS_KEEPALIVE=$NEXUS_KEEPALIVE

ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
ENV SENTRY_PROJECT=$SENTRY_PROJECT
ENV SENTRY_ORG=$SENTRY_ORG
ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN
ENV VERCEL_GIT_COMMIT_SHA=$VERCEL_GIT_COMMIT_SHA

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

Expand Down
16 changes: 13 additions & 3 deletions lib/auth/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// constants.ts TS-Doc?
/* eslint @typescript-eslint/consistent-type-assertions:0 */
import _ from 'lodash';
import type { NextAuthConfig } from 'next-auth';
import { v4 as uuid } from 'uuid';
import type { PrismaClient } from '@prisma/client';
Expand Down Expand Up @@ -40,17 +41,21 @@ export const GetSession = async ({ cookies = '' }) => {

// schema sanitizer
const allUsersSideEffects = async ({ user }: any) => {
if (!user) return;
const services = await GetPrivateCommonServices({});
const abilities = await GetPrivateCommonAbilities({});
const commonServices = services.map((service: any) => service?.id).map((el: any) => el);
const commonAbilities = abilities.map((ability: any) => ability?.id).map((el: any) => el);

const [dpcpAbility] = await GetPrivateAbilities({ type: 'R', target: 'dpcp-vibemodulator', action: 'view-listings' });

await UpdatePrivateUserServices({ user, services: [...commonServices, ...user.servicesIds], upsert: false });
const nextAbilities = _.uniq([...commonAbilities, ...user.abilitiesIds, dpcpAbility?.id]);
const nextServices = _.uniq([...commonServices, ...user.servicesIds]);

await UpdatePrivateUserServices({ user, services: nextServices, upsert: false });
await UpdatePrivateUserAbilities({
user,
abilities: [...commonAbilities, ...user.abilitiesIds, dpcpAbility.id],
abilities: nextAbilities,
upsert: false,
});
};
Expand Down Expand Up @@ -114,6 +119,7 @@ export const authConfig = {
const { user, isNewUser } = props;
try {
if (isNewUser) {
console.log('Events: Running side-effects');
await allUsersSideEffects({ user });
}
} catch (e) {
Expand All @@ -126,8 +132,12 @@ export const authConfig = {
callbacks: {
async signIn(props) {
const { user } = props;
console.log({ props, user });
try {
await allUsersSideEffects({ user });
if (user) {
console.log('Callback: Running side-effects');
await allUsersSideEffects({ user });
}
} catch (e) {
console.warn(`Code 004: Log-in side-effects failed. If it's a new user, plese ignore: ${e}`);
}
Expand Down
20 changes: 14 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@prisma/extension-accelerate": "1.1.0",
"@prisma/nextjs-monorepo-workaround-plugin": "5.18.0",
"@types/json-schema": "7.0.15",
"@types/lodash": "^4.17.7",
"@types/node": "20",
"@types/react": "18.3.2",
"@types/uuid": "9.0.8",
Expand All @@ -73,7 +74,7 @@
"eslint-config-alloy": "5.1.2",
"eslint-config-next": "14.0.4",
"husky": "9.0.11",
"lodash": "4.17.21",
"lodash": "^4.17.21",
"mongodb": "5.0.0",
"next-auth": "5.0.0-beta.20",
"nodemailer": "6.9.14",
Expand Down
1 change: 1 addition & 0 deletions src/app/api/v1/public/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const generateErrorResponse = (e: any, status: number) => {
};

// export const dynamic = 'force-static';

export async function GET(request: CombineRequest) {
try {
const url = new URL(request.url);
Expand Down
1 change: 1 addition & 0 deletions src/app/api/v1/services/dpcp-vibemodulator/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const generateErrorResponse = (e: any, status: number) => {
};

// export const dynamic = 'force-static';

export async function GET(request: CombineRequest) {
try {
const cookies = request?.cookies?.toString() || request?.headers?.get('cookies');
Expand Down
1 change: 1 addition & 0 deletions src/app/api/v1/services/rickmorty/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const generateErrorResponse = (e: any, status: number) => {
};

// export const dynamic = 'force-static';

export async function GET(request: CombineRequest) {
try {
const url = new URL(request.url);
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/v1/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const generateErrorResponse = (e: any, status: number) => {
};
};

// export const dynamic = 'force-static';
export const dynamic = 'force-dynamic';

export async function POST(request: CombineRequest) {
const response = { error: generateErrorResponse({ message: 'Code 000/0: Non-identified error.' }, 500) };
Expand Down
Loading