Skip to content

Commit

Permalink
Merge pull request #199 from yocxo/srizvi/issue174
Browse files Browse the repository at this point in the history
chore: merge upstream changes #174
  • Loading branch information
srizvi authored Mar 27, 2024
2 parents fa2fa2a + 3cc6385 commit b19997b
Show file tree
Hide file tree
Showing 46 changed files with 823 additions and 706 deletions.
9 changes: 8 additions & 1 deletion apps/auth-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Deploy it somewhere (Vercel is a one-click, zero-config option) and set the foll
- `AUTH_REDIRECT_PROXY_URL` - The URL of this proxy server
- `AUTH_SECRET` - Your secret

Make sure the `AUTH_SECRET` and `AUTH_REDIRECT_PROXY_URL` match the values set for the main application's deployment for preview environments, and that you're using the same OAuth credentials for the proxy and the application's preview environment. The lines below shows what values should match eachother in both deployments.
Make sure the `AUTH_SECRET` and `AUTH_REDIRECT_PROXY_URL` match the values set for the main application's deployment for preview environments, and that you're using the same OAuth credentials for the proxy and the application's preview environment.
`AUTH_REDIRECT_PROXY_URL` should only be set for the main application's preview environment. Do not set it for the production environment.

The lines below shows what values should match eachother in both deployments.

![Environment variables setup](https://github.com/t3-oss/create-t3-turbo/assets/51714798/5fadd3f5-f705-459a-82ab-559a3df881d0)

For providers that require an origin and a redirect URL, set them to `{AUTH_REDIRECT_PROXY_URL}` and `{AUTH_REDIRECT_PROXY_URL}/callback/{provider}` accordingly.

![Google credentials setup](https://github.com/ahkhanjani/create-t3-turbo/assets/72540492/eaa88685-6fc2-4c23-b7ac-737eb172fa0e)
16 changes: 8 additions & 8 deletions apps/auth-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@auth/core": "0.27.0"
"@auth/core": "0.28.1"
},
"devDependencies": {
"@yocxo/eslint-config": "workspace:^0.2.0",
"@yocxo/prettier-config": "workspace:^0.1.0",
"@yocxo/tailwind-config": "workspace:^0.1.0",
"@yocxo/tsconfig": "workspace:^0.1.0",
"@types/node": "^20.11.25",
"@yocxo/eslint-config": "workspace:*",
"@yocxo/prettier-config": "workspace:*",
"@yocxo/tailwind-config": "workspace:*",
"@yocxo/tsconfig": "workspace:*",
"@types/node": "^20.11.30",
"eslint": "^8.57.0",
"h3": "^1.11.1",
"nitropack": "^2.8.1",
"nitropack": "^2.9.4",
"prettier": "^3.2.5",
"typescript": "^5.3.3"
"typescript": "^5.4.3"
},
"eslintConfig": {
"root": true,
Expand Down
7 changes: 3 additions & 4 deletions apps/coco/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { fileURLToPath } from 'url';

import _jiti from 'jiti';
import createJiti from 'jiti';

const jiti = _jiti(fileURLToPath(import.meta.url));

jiti('./src/env');
// Import env files to validate at build time. Use jiti so we can load .ts files in here.
createJiti(fileURLToPath(import.meta.url))('./src/env');

/** @type {import("next").NextConfig} */
const config = {
Expand Down
30 changes: 15 additions & 15 deletions apps/coco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"with-env": "dotenv -e .env.local --"
},
"dependencies": {
"@yocxo/api": "workspace:^0.1.0",
"@yocxo/auth": "workspace:^0.1.0",
"@yocxo/db": "workspace:^0.1.0",
"@yocxo/ui": "workspace:^0.1.0",
"@yocxo/validators": "workspace:^0.1.0",
"@yocxo/api": "workspace:*",
"@yocxo/auth": "workspace:*",
"@yocxo/db": "workspace:*",
"@yocxo/ui": "workspace:*",
"@yocxo/validators": "workspace:*",
"@t3-oss/env-nextjs": "^0.9.2",
"@vercel/analytics": "^1.1.2",
"@vercel/kv": "^1.0.1",
Expand All @@ -29,8 +29,8 @@
"focus-trap-react": "^10.2.3",
"framer-motion": "^11.0.5",
"nanoid": "^5.0.4",
"next": "^14.1.0",
"next-auth": "5.0.0-beta.13",
"next": "^14.1.4",
"next-auth": "5.0.0-beta.16",
"openai": "^4.24.7",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -44,21 +44,21 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@yocxo/eslint-config": "workspace:^0.2.0",
"@yocxo/prettier-config": "workspace:^0.1.0",
"@yocxo/tailwind-config": "workspace:^0.1.0",
"@yocxo/tsconfig": "workspace:^0.1.0",
"@yocxo/eslint-config": "workspace:*",
"@yocxo/prettier-config": "workspace:*",
"@yocxo/tailwind-config": "workspace:*",
"@yocxo/tsconfig": "workspace:*",
"@types/d3-scale": "^4.0.8",
"@types/node": "^20.11.25",
"@types/react": "^18.2.67",
"@types/node": "^20.11.30",
"@types/react": "^18.2.69",
"@types/react-dom": "^18.2.22",
"@types/react-syntax-highlighter": "^15.5.11",
"dotenv-cli": "^7.3.0",
"dotenv-cli": "^7.4.1",
"eslint": "^8.57.0",
"jiti": "^1.21.0",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
"typescript": "^5.4.3"
},
"eslintConfig": {
"root": true,
Expand Down
5 changes: 3 additions & 2 deletions apps/coco/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { ThemeToggle } from '@yocxo/ui/theme';
import { Toaster } from '@yocxo/ui/toast';

import { siteConfig } from '#/config/site';
import { env } from '#/env';
import { Header } from '#/ui/header';
import { Providers } from '#/ui/providers';

export const metadata = {
metadataBase: new URL(
env.VERCEL_ENV === 'production' ? siteConfig.url : 'http://localhost:3003',
process.env.VERCEL_ENV === 'production'
? siteConfig.url
: 'http://localhost:3003',
),
title: {
template: `%s :: ${siteConfig.name}`,
Expand Down
2 changes: 0 additions & 2 deletions apps/coco/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const env = createEnv({
NODE_ENV: z
.enum(['development', 'production', 'test'])
.default('development'),
VERCEL_ENV: z.enum(['development', 'preview', 'production']).optional(),
},
server: {
AUTH_SECRET: z.string(),
Expand All @@ -29,7 +28,6 @@ export const env = createEnv({
NEXT_PUBLIC_APP_URL: process.env.NEXT_PUBLIC_APP_URL,
NODE_ENV: process.env.NODE_ENV,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
VERCEL_ENV: process.env.VERCEL_ENV,
},
skipValidation:
!!process.env.CI ||
Expand Down
5 changes: 4 additions & 1 deletion apps/coco/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"extends": "@yocxo/tsconfig/base.json",
"compilerOptions": {
"lib": ["es2022", "dom", "dom.iterable"],
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"#/*": ["./src/*"]
},
"plugins": [{ "name": "next" }],
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"module": "esnext"
},
"include": [".", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
Expand Down
40 changes: 20 additions & 20 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@expo/metro-config": "^0.17.4",
"@expo/metro-config": "^0.17.6",
"@shopify/flash-list": "1.6.3",
"@tanstack/react-query": "^5.22.2",
"@trpc/client": "11.0.0-next-beta.294",
"@trpc/react-query": "11.0.0-next-beta.294",
"@trpc/server": "11.0.0-next-beta.294",
"expo": "~50.0.7",
"@tanstack/react-query": "^5.28.6",
"@trpc/client": "11.0.0-next.320",
"@trpc/react-query": "11.0.0-next.320",
"@trpc/server": "11.0.0-next.320",
"expo": "~50.0.14",
"expo-constants": "~15.4.5",
"expo-linking": "~6.2.2",
"expo-router": "~3.4.7",
"expo-router": "~3.4.8",
"expo-splash-screen": "~0.26.4",
"expo-status-bar": "~1.11.1",
"nativewind": "~4.0.36",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "~0.73.5",
"react-native-css-interop": "~0.0.13",
"react-native-gesture-handler": "~2.14.0",
"react-native": "~0.73.6",
"react-native-css-interop": "~0.0.34",
"react-native-gesture-handler": "~2.14.1",
"react-native-reanimated": "~3.8.1",
"react-native-safe-area-context": "~4.8.2",
"react-native-screens": "~3.29.0",
"superjson": "2.2.1"
},
"devDependencies": {
"@yocxo/api": "workspace:^0.1.0",
"@yocxo/eslint-config": "workspace:^0.2.0",
"@yocxo/prettier-config": "workspace:^0.1.0",
"@yocxo/tailwind-config": "workspace:^0.1.0",
"@yocxo/tsconfig": "workspace:^0.1.0",
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/runtime": "^7.23.9",
"@yocxo/api": "workspace:*",
"@yocxo/eslint-config": "workspace:*",
"@yocxo/prettier-config": "workspace:*",
"@yocxo/tailwind-config": "workspace:*",
"@yocxo/tsconfig": "workspace:*",
"@babel/core": "^7.24.3",
"@babel/preset-env": "^7.24.3",
"@babel/runtime": "^7.24.1",
"@types/babel__core": "^7.20.5",
"@types/react": "^18.2.67",
"@types/react": "^18.2.69",
"eslint": "^8.57.0",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
"typescript": "^5.4.3"
},
"eslintConfig": {
"root": true,
Expand Down
3 changes: 2 additions & 1 deletion apps/expo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"jsx": "react-native",
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"types": ["nativewind/types"]
"types": ["nativewind/types"],
"checkJs": false
},
"include": ["src", "*.ts", "*.js", ".expo/types/**/*.ts", "expo-env.d.ts"],
"exclude": ["node_modules"]
Expand Down
7 changes: 2 additions & 5 deletions apps/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { fileURLToPath } from 'url';

import _jiti from 'jiti';

const jiti = _jiti(fileURLToPath(import.meta.url));
import createJiti from 'jiti';

// Import env files to validate at build time. Use jiti so we can load .ts files in here.
jiti('./src/env');
jiti('@yocxo/auth/env');
createJiti(fileURLToPath(import.meta.url))('./src/env');

/** @type {import("next").NextConfig} */
const config = {
Expand Down
38 changes: 19 additions & 19 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@
"with-env": "dotenv -e ../../.env --"
},
"dependencies": {
"@yocxo/api": "workspace:^0.1.0",
"@yocxo/auth": "workspace:^0.1.0",
"@yocxo/db": "workspace:^0.1.0",
"@yocxo/ui": "workspace:^0.1.0",
"@yocxo/validators": "workspace:^0.1.0",
"@yocxo/api": "workspace:*",
"@yocxo/auth": "workspace:*",
"@yocxo/db": "workspace:*",
"@yocxo/ui": "workspace:*",
"@yocxo/validators": "workspace:*",
"@t3-oss/env-nextjs": "^0.9.2",
"@tanstack/react-query": "^5.22.2",
"@trpc/client": "11.0.0-next-beta.294",
"@trpc/react-query": "11.0.0-next-beta.294",
"@trpc/server": "11.0.0-next-beta.294",
"geist": "^1.2.2",
"next": "^14.1.0",
"@tanstack/react-query": "^5.28.6",
"@trpc/client": "11.0.0-next.320",
"@trpc/react-query": "11.0.0-next.320",
"@trpc/server": "11.0.0-next.320",
"geist": "^1.3.0",
"next": "^14.1.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "2.2.1",
"zod": "^3.22.4"
},
"devDependencies": {
"@yocxo/eslint-config": "workspace:^0.2.0",
"@yocxo/prettier-config": "workspace:^0.1.0",
"@yocxo/tailwind-config": "workspace:^0.1.0",
"@yocxo/tsconfig": "workspace:^0.1.0",
"@types/node": "^20.11.25",
"@types/react": "^18.2.67",
"@yocxo/eslint-config": "workspace:*",
"@yocxo/prettier-config": "workspace:*",
"@yocxo/tailwind-config": "workspace:*",
"@yocxo/tsconfig": "workspace:*",
"@types/node": "^20.11.30",
"@types/react": "^18.2.69",
"@types/react-dom": "^18.2.22",
"dotenv-cli": "^7.3.0",
"dotenv-cli": "^7.4.1",
"eslint": "^8.57.0",
"jiti": "^1.21.0",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
"typescript": "^5.4.3"
},
"eslintConfig": {
"root": true,
Expand Down
52 changes: 1 addition & 51 deletions apps/nextjs/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
import type { NextRequest } from 'next/server';

import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';

import { GET as DEFAULT_GET, POST } from '@yocxo/auth';
export { GET, POST } from '@yocxo/auth';

export const runtime = 'edge';

const EXPO_COOKIE_NAME = '__acme-expo-redirect-state';
const AUTH_COOKIE_PATTERN = /authjs\.session-token=([^;]+)/;

const getToken = (res: Response) => {
for (const candidate of res.headers.getSetCookie()) {
const match = candidate.match(AUTH_COOKIE_PATTERN);
if (match?.[1]) return match[1];
}
throw new Error('Unable to find session cookie');
};

export const GET = async (
req: NextRequest,
props: { params: { nextauth: string[] } },
) => {
const nextauthAction = props.params.nextauth[0];
const isExpoSignIn = req.nextUrl.searchParams.get('expo-redirect');
const isExpoCallback = cookies().get(EXPO_COOKIE_NAME);

if (nextauthAction === 'signin' && !!isExpoSignIn) {
// set a cookie we can read in the callback
// to know to send the user back to expo
cookies().set({
name: EXPO_COOKIE_NAME,
value: isExpoSignIn,
maxAge: 60 * 10, // 10 min
path: '/',
});
}

if (nextauthAction === 'callback' && !!isExpoCallback) {
cookies().delete(EXPO_COOKIE_NAME);

const authResponse = await DEFAULT_GET(req);
const url = new URL(isExpoCallback.value);
url.searchParams.set('session_token', getToken(authResponse));
return NextResponse.redirect(url);
}

// Every other request just calls the default handler
return DEFAULT_GET(req);
};

export { POST };
3 changes: 1 addition & 2 deletions apps/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { cn } from '@yocxo/ui';
import { ThemeProvider, ThemeToggle } from '@yocxo/ui/theme';
import { Toaster } from '@yocxo/ui/toast';

import { env } from '#/env';
import { TRPCReactProvider } from '#/trpc/react';

import '#/app/globals.css';

export const metadata: Metadata = {
metadataBase: new URL(
env.VERCEL_ENV === 'production'
process.env.VERCEL_ENV === 'production'
? 'https://turbo.t3.gg'
: 'http://localhost:3000',
),
Expand Down
Loading

0 comments on commit b19997b

Please sign in to comment.