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

Release to Production #384

Merged
merged 5 commits into from
Aug 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
19 changes: 19 additions & 0 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ベースイメージを指定(例:Node.jsの公式イメージの最新LTS版)
FROM node:20

# 作業ディレクトリを作成
WORKDIR /app

# アプリケーションのソースコードをコピー
COPY . .

RUN git clean -xdf

# 依存関係をインストール
RUN npm install

# アプリケーションを起動
CMD ["npm", "run", "dev"]

# ポート番号を指定(例:3000)
EXPOSE 3000
29 changes: 29 additions & 0 deletions docker-compose.e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
db:
image: postgres:16-alpine
restart: always
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
nextjs:
build:
context: .
dockerfile: Dockerfile.e2e
ports:
- 3000:3000
depends_on:
- db
environment:
SUPABASE_POSTGRES_URL_NON_POOLING: postgres://postgres:postgres@db:5432/postgres
SUPABASE_POSTGRES_PRISMA_URL: postgres://postgres:postgres@db:5432/postgres?pgbouncer=true
MOCK_LOGIN: 1
RANKING_WEIGHT: '{"questionLogsLength": -0.1,"correctSolutionsLength": 0.3,"evaluationTotal": 0.9,"questionExamplesLength": 0.4,"random": 2,"timeFromPublished": -0.2}'
NEXTAUTH_SECRET: 'secret'
OPENAI_API_KEY: ${OPENAI_API_KEY}
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY}
EDGE_CONFIG: ${EDGE_CONFIG}


44 changes: 22 additions & 22 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"mustache": "4.2.0",
"next": "14.2.5",
"next-auth": "4.24.7",
"openai": "4.55.5",
"openai": "4.55.7",
"randomstring": "1.3.0",
"react": "18.3.1",
"react-copy-to-clipboard": "5.1.0",
Expand Down Expand Up @@ -96,7 +96,7 @@
"storybook": "8.2.9",
"ts-node": "10.9.2",
"typescript": "5.5.4",
"vercel": "35.2.4",
"vercel": "36.0.0",
"vitest": "2.0.5"
},
"lint-staged": {
Expand Down
32 changes: 8 additions & 24 deletions src/app/stories/[storyId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { brand } from "@/common/texts";
import { uaToDevice } from "@/common/util/device";
import { Play } from "@/components/play";
import { StoryDescription } from "@/components/storyDescription";
import type { Story } from "@/server/model/story";
Expand All @@ -15,13 +14,12 @@ import {
unpublishStory,
} from "@/server/services/story/publishStory";
import { postStoryEvalution } from "@/server/services/storyEvalution/post";
import { get } from "@vercel/edge-config";
import { getQuestionLimitation } from "@/server/services/user/limitation";
import { Metadata } from "next";
import { revalidateTag } from "next/cache";
import { cookies, headers } from "next/headers";
import { cookies } from "next/headers";
import { notFound } from "next/navigation";
import { cache } from "react";
import { z } from "zod";
import { MyStoryMenu } from "../../../components/myStoryMenu";
import styles from "./page.module.scss";

Expand Down Expand Up @@ -82,10 +80,6 @@ export const generateStaticParams = async () => {
}));
};

const questionLimitationSchema = z.object({
desktopOnly: z.boolean(),
});

const MyStoryMenuServer = async ({ story }: { story: Story }) => {
const session = await getUserSession().catch((e) => {
console.error(e);
Expand Down Expand Up @@ -160,24 +154,14 @@ export default async function StoryPage({ params: { storyId } }: StoryProps) {
story={story}
fetchCanPlay={async () => {
"use server";
const thankyouCookie = cookies().get("thankyou");
if (
thankyouCookie &&
thankyouCookie.value === process.env.THANKYOU_CODE
) {
return {
canPlay: true,
};
}
const questionLimitation = questionLimitationSchema.parse(
await get("questionLimitation"),
);

const device = getDevice();
if (questionLimitation.desktopOnly && device !== "desktop") {
const limited = await getQuestionLimitation({
device: getDevice(),
getCookie: (key) => cookies().get(key)?.value || null,
});
if (limited) {
return {
canPlay: false,
reason: "desktop_only",
reason: limited,
};
}
return {
Expand Down
128 changes: 85 additions & 43 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,94 @@ import { generateId } from "@/common/util/id";
import { neverReach } from "@/common/util/never";
import { prisma } from "@/libs/prisma";
import NextAuth, { type NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import GoogleProvider from "next-auth/providers/google";

if (
!process.env.GOOGLE_ID ||
!process.env.GOOGLE_SECRET ||
!process.env.NEXTAUTH_SECRET
) {
throw new Error("Google OAuth is not configured");
}

export const authConfig: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
}),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async jwt({ token, account }) {
if (account?.providerAccountId && !token?.userId) {
// 初回ログイン時のみuserが存在します
const user = await prisma.user.upsert({
where: { oauthId: account.providerAccountId },
update: {},
create: {
id: generateId(),
oauthId: account.providerAccountId,
export const authConfig: NextAuthOptions =
process.env.GOOGLE_ID && process.env.GOOGLE_SECRET
? {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
}),
],
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
async jwt({ token, account }) {
if (account?.providerAccountId && !token?.userId) {
// 初回ログイン時のみuserが存在します
const user = await prisma.user.upsert({
where: { oauthId: account.providerAccountId },
update: {},
create: {
id: generateId(),
oauthId: account.providerAccountId,
},
});
const userId: string = user.id;
token.userId = userId; // userオブジェクトに保存されているカスタム値をトークンに追加します
}
return token;
},
async session({ session, token }) {
// トークンからセッションにカスタム値を追加します
session.custom = {
userId:
typeof token.userId === "string"
? token.userId
: neverReach("token.userId is not string"),
};
return session;
},
});
const userId: string = user.id;
token.userId = userId; // userオブジェクトに保存されているカスタム値をトークンに追加します
},
}
return token;
},
async session({ session, token }) {
// トークンからセッションにカスタム値を追加します
session.custom = {
userId:
typeof token.userId === "string"
? token.userId
: neverReach("token.userId is not string"),
};
return session;
},
},
};
: process.env.MOCK_LOGIN
? {
providers: [
CredentialsProvider({
credentials: {
id: { label: "id", type: "text", placeholder: "User Id" },
},
authorize: function (credentials) {
return credentials?.id
? {
id: credentials.id,
email: "[email protected]",
}
: null;
},
}),
],
secret: "secret",
callbacks: {
async jwt({ user, token }) {
if (user) {
// 初回ログイン時のみuserが存在します
const createdUser = await prisma.user.upsert({
where: { oauthId: user.id },
update: {},
create: {
id: user.id,
},
});
const userId: string = createdUser.id;
token.userId = userId; // userオブジ
}
return token;
},
async session({ session, token }) {
// トークンからセッションにカスタム値を追加します
session.custom = {
userId:
typeof token.userId === "string"
? token.userId
: neverReach("token.userId is not string"),
};
return session;
},
},
}
: neverReach("Google OAuth is not configured");

export default NextAuth(authConfig);
Loading