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

Fix api/auth route conflict #9153

Merged
merged 4 commits into from
Feb 15, 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
2 changes: 1 addition & 1 deletion app/changelog/%5Fadmin/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {type ReactNode, Suspense} from 'react';
import {GET} from 'app/api/auth/[...nextauth]/route';
import {GET} from 'app/changelog/api/auth/[...nextauth]/route';
import {getServerSession} from 'next-auth/next';

import LoginButton from 'sentry-docs/components/changelog/loginButton';
Expand Down
2 changes: 1 addition & 1 deletion app/changelog/%5Fadmin/upload/route.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from 'crypto';

import {Storage} from '@google-cloud/storage';
import {GET as sessionHandler} from 'app/api/auth/[...nextauth]/route';
import {GET as sessionHandler} from 'app/changelog/api/auth/[...nextauth]/route';
import {NextRequest} from 'next/server';
import {getServerSession} from 'next-auth/next';

Expand Down
2 changes: 1 addition & 1 deletion app/changelog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Fragment, Suspense} from 'react';
import {type Category, type Changelog} from '@prisma/client';
import * as Sentry from '@sentry/nextjs';
import {GET} from 'app/api/auth/[...nextauth]/route';
import {GET} from 'app/changelog/api/auth/[...nextauth]/route';
import type {Metadata, ResolvingMetadata} from 'next';
import Link from 'next/link';
import {getServerSession} from 'next-auth/next';
Expand Down
2 changes: 1 addition & 1 deletion src/actions/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server';

import {GET as handler} from 'app/api/auth/[...nextauth]/route';
import {GET as handler} from 'app/changelog/api/auth/[...nextauth]/route';
import {revalidatePath} from 'next/cache';
import {redirect} from 'next/navigation';
import {getServerSession} from 'next-auth/next';
Expand Down
28 changes: 14 additions & 14 deletions src/build/resolveOpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import {promises as fs} from 'fs';

import {cache} from 'react';

import {DeRefedOpenAPI} from './open-api/types';

// SENTRY_API_SCHEMA_SHA is used in the sentry-docs GHA workflow in getsentry/sentry-api-schema.
Expand All @@ -14,8 +12,6 @@ const SENTRY_API_SCHEMA_SHA = '76490f725fda1363e3412c8462a95567832a68ac';

const activeEnv = process.env.GATSBY_ENV || process.env.NODE_ENV || 'development';

let cachedResonse: DeRefedOpenAPI | null = null;

async function resolveOpenAPI(): Promise<DeRefedOpenAPI> {
if (activeEnv === 'development' && process.env.OPENAPI_LOCAL_PATH) {
try {
Expand All @@ -29,16 +25,10 @@ async function resolveOpenAPI(): Promise<DeRefedOpenAPI> {
);
}
}

if (cachedResonse) {
return cachedResonse;
}
const response = await fetch(
`https://raw.githubusercontent.com/getsentry/sentry-api-schema/${SENTRY_API_SCHEMA_SHA}/openapi-derefed.json`,
{cache: 'no-store'}
`https://raw.githubusercontent.com/getsentry/sentry-api-schema/${SENTRY_API_SCHEMA_SHA}/openapi-derefed.json`
);
cachedResonse = await response.json();
return cachedResonse!;
return await response.json();
}

export type APIParameter = {
Expand Down Expand Up @@ -85,7 +75,17 @@ function slugify(s: string): string {
.toLowerCase();
}

export const apiCategories = cache(async (): Promise<APICategory[]> => {
let apiCategoriesCache: Promise<APICategory[]> | undefined;

export function apiCategories(): Promise<APICategory[]> {
if (apiCategoriesCache) {
return apiCategoriesCache;
}
apiCategoriesCache = apiCategoriesUncached();
return apiCategoriesCache;
}

async function apiCategoriesUncached(): Promise<APICategory[]> {
const data = await resolveOpenAPI();

const categoryMap: {[name: string]: APICategory} = {};
Expand Down Expand Up @@ -150,7 +150,7 @@ export const apiCategories = cache(async (): Promise<APICategory[]> => {
c.apis.sort((a, b) => a.name.localeCompare(b.name));
});
return categories;
});
}

function getBodyParameters(apiData): APIParameter[] {
const content = apiData.requestBody?.content;
Expand Down
Loading