mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
feat: migrate nextjs to rr7
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { APP_BASE_URL } from '@documenso/lib/constants/app';
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||
|
||||
import { FREE_PLAN_LIMITS } from './constants';
|
||||
import type { TLimitsResponseSchema } from './schema';
|
||||
@ -12,7 +12,7 @@ export type GetLimitsOptions = {
|
||||
export const getLimits = async ({ headers, teamId }: GetLimitsOptions = {}) => {
|
||||
const requestHeaders = headers ?? {};
|
||||
|
||||
const url = new URL('/api/limits', APP_BASE_URL() ?? 'http://localhost:3000');
|
||||
const url = new URL('/api/limits', NEXT_PUBLIC_WEBAPP_URL());
|
||||
|
||||
if (teamId) {
|
||||
requestHeaders['team-id'] = teamId.toString();
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import { getToken } from 'next-auth/jwt';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||
|
||||
import { ERROR_CODES } from './errors';
|
||||
import type { TLimitsErrorResponseSchema, TLimitsResponseSchema } from './schema';
|
||||
import { getServerLimits } from './server';
|
||||
|
||||
export const limitsHandler = async (
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<TLimitsResponseSchema | TLimitsErrorResponseSchema>,
|
||||
) => {
|
||||
try {
|
||||
const token = await getToken({ req });
|
||||
// res: NextApiResponse<TLimitsResponseSchema | TLimitsErrorResponseSchema>,
|
||||
|
||||
const rawTeamId = req.headers['team-id'];
|
||||
export const limitsHandler = async (req: Request) => {
|
||||
try {
|
||||
// Todo: Check
|
||||
const { user } = await getSession(req);
|
||||
|
||||
const rawTeamId = req.headers.get('team-id');
|
||||
|
||||
let teamId: number | null = null;
|
||||
|
||||
@ -26,9 +24,11 @@ export const limitsHandler = async (
|
||||
throw new Error(ERROR_CODES.INVALID_TEAM_ID);
|
||||
}
|
||||
|
||||
const limits = await getServerLimits({ email: token?.email, teamId });
|
||||
const limits = await getServerLimits({ email: user?.email, teamId });
|
||||
|
||||
return res.status(200).json(limits);
|
||||
return Response.json(limits, {
|
||||
status: 200,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('error', err);
|
||||
|
||||
@ -37,13 +37,23 @@ export const limitsHandler = async (
|
||||
.with(ERROR_CODES.UNAUTHORIZED, () => 401)
|
||||
.otherwise(() => 500);
|
||||
|
||||
return res.status(status).json({
|
||||
error: ERROR_CODES[err.message] ?? ERROR_CODES.UNKNOWN,
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
error: ERROR_CODES[err.message] ?? ERROR_CODES.UNKNOWN,
|
||||
},
|
||||
{
|
||||
status,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return res.status(500).json({
|
||||
error: ERROR_CODES.UNKNOWN,
|
||||
});
|
||||
return Response.json(
|
||||
{
|
||||
error: ERROR_CODES.UNKNOWN,
|
||||
},
|
||||
{
|
||||
status: 500,
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
'use client';
|
||||
|
||||
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
||||
|
||||
import { isDeepEqual } from 'remeda';
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import { headers } from 'next/headers';
|
||||
|
||||
import { getLimits } from '../client';
|
||||
import { LimitsProvider as ClientLimitsProvider } from './client';
|
||||
|
||||
export type LimitsProviderProps = {
|
||||
children?: React.ReactNode;
|
||||
teamId?: number;
|
||||
};
|
||||
|
||||
export const LimitsProvider = async ({ children, teamId }: LimitsProviderProps) => {
|
||||
const requestHeaders = Object.fromEntries(headers().entries());
|
||||
|
||||
const limits = await getLimits({ headers: requestHeaders, teamId });
|
||||
|
||||
return (
|
||||
<ClientLimitsProvider initialValue={limits} teamId={teamId}>
|
||||
{children}
|
||||
</ClientLimitsProvider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user