-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); |