Skip to content

Commit 3c8d155

Browse files
authored
任意のメールアドレスでログインを可能にする (#509)
<!--変更したい場合は、`/.github/pull_request_template.md` を修正して下さい。--> # PRの概要 <!-- 変更の目的 もしくは 関連する Issue 番号 --> <!-- 以下のように書くと Issue にリンクでき、マージ時に自動で Issue を閉じられる--> <!-- closes #1 --> ## 具体的な変更内容 <!-- ビューの変更がある場合はスクショによる比較などがあるとわかりやすい --> ## 影響範囲 <!-- この関数を変更したのでこの機能にも影響がある、など --> ## 動作要件 <!-- 動作に必要な 環境変数 / 依存関係 / DBの更新 など --> ## 補足 <!-- レビューをする際に見てほしい点、ローカル環境で試す際の注意点、など --> ## レビューリクエストを出す前にチェック! - [x] 改めてセルフレビューしたか - [x] 手動での動作検証を行ったか - [ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [x] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 -->
1 parent a3a8e5c commit 3c8d155

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,18 @@ make docker
5959
# または
6060
make docker-watch
6161
```
62+
63+
## Deploy
64+
65+
web:
66+
```sh
67+
VITE_ALLOW_ANY_MAIL_ADDR=true # optional
68+
make prepare-deploy-web`
69+
# serve ./web/dist
70+
```
71+
72+
server:
73+
```sh
74+
make prepare-deploy-server
75+
make deploy-server
76+
```

web/.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ VITE_FIREBASE_PROJECT_ID=example
66
# VITE_FIREBASE_MESSAGING_SENDER_ID=example
77
VITE_FIREBASE_APP_ID=example
88
VITE_FIREBASE_MEASUREMENT_ID=example
9+
VITE_ALLOW_ANY_MAIL_ADDR=true
910

1011
#supabase
1112
VITE_SUPABASE_URL=

web/src/routes/login.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ import { CourseMateIcon } from "../components/common/CourseMateIcon";
1313
import FullScreenCircularProgress from "../components/common/FullScreenCircularProgress";
1414

1515
const provider = new GoogleAuthProvider();
16+
const ALLOW_ANY_MAIL_ADDR = import.meta.env.VITE_ALLOW_ANY_MAIL_ADDR === "true";
1617

1718
async function signInWithGoogle() {
1819
try {
19-
provider.setCustomParameters({
20-
hd: "g.ecc.u-tokyo.ac.jp",
21-
});
20+
if (!ALLOW_ANY_MAIL_ADDR) {
21+
provider.setCustomParameters({
22+
hd: "g.ecc.u-tokyo.ac.jp",
23+
});
24+
}
2225
const result = await signInWithPopup(auth, provider);
2326
const credential = GoogleAuthProvider.credentialFromResult(result);
2427

@@ -29,7 +32,10 @@ async function signInWithGoogle() {
2932
const user = result.user;
3033
const email = user.email;
3134

32-
if (!email || !email.endsWith("@g.ecc.u-tokyo.ac.jp")) {
35+
if (
36+
!ALLOW_ANY_MAIL_ADDR &&
37+
(!email || !email.endsWith("@g.ecc.u-tokyo.ac.jp"))
38+
) {
3339
throw new Error(
3440
"Unauthorized domain. Access is restricted to g.ecc.u-tokyo.ac.jp domain.",
3541
);

0 commit comments

Comments
 (0)