{"id":21413186,"url":"https://github.com/github0013/nextjs-auth0-google","last_synced_at":"2025-07-04T16:06:39.419Z","repository":{"id":42872549,"uuid":"257812833","full_name":"github0013/nextjs-auth0-google","owner":"github0013","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-24T02:14:32.000Z","size":1234,"stargazers_count":1,"open_issues_count":12,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-16T18:22:59.281Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/github0013.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-22T06:32:55.000Z","updated_at":"2020-06-28T15:38:21.000Z","dependencies_parsed_at":"2023-02-13T11:31:06.043Z","dependency_job_id":null,"html_url":"https://github.com/github0013/nextjs-auth0-google","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/github0013/nextjs-auth0-google","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0013%2Fnextjs-auth0-google","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0013%2Fnextjs-auth0-google/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0013%2Fnextjs-auth0-google/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0013%2Fnextjs-auth0-google/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github0013","download_url":"https://codeload.github.com/github0013/nextjs-auth0-google/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github0013%2Fnextjs-auth0-google/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263573057,"owners_count":23482575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T18:17:26.665Z","updated_at":"2025-07-04T16:06:39.400Z","avatar_url":"https://github.com/github0013.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nextjs + auth0 + google (reload でもログインキープ)サンプル\n\nhttps://github.com/Swizec/useAuth\n\nauth0 はこのパッケージでだいぶ楽だが、google などの ID プロバイダーなどでのログインとなるとやっかいで、ログイン後にリロードするとログアウト状態になる。\nこれはセキュリティの観点上重要な情報はメモリ内にあるだけなので、リロードすると消えてしまう。\n\nこのパッケージにもあるように、Google でリロード後もログイン状態を保つには以下の通りにする。\n\nSet Up Social Connections\nhttps://auth0.com/docs/dashboard/guides/connections/set-up-connections-social\n\n参考:\nReact Tutorial: Building and Securing Your First App\n(Keeping Users Signed In after a Refresh から読む)\nhttps://auth0.com/blog/react-tutorial-building-and-securing-your-first-app/\n\nこれを読んでいってもちょっと分かりにくかったので、このサンプル環境と手順で簡単に試せます。\n\n## 事前準備\n\n1. gmail のアカウントがある（あとで google API console にログインする必要がある）\n1. ngrok にアカウントがある（すぐ作れる - 外から繋がる https が必要）\n1. ngrok の authtoken がある（ログイン後、通常表示される）\n1. auth0 にアカウントがある\n1. auth0 に app がある\n1. auth0 に Google の connection がある\n1. docker-compose.yml の`YOUR_NGROK_AUTH`に ngrok の authtoken を入れる\n1. ./frontend に .env を作る（.env.EXAMPLE 参考）\n1. auth0 を開いて app の`Allowed Callback URLs`、`Allowed Logout URLs`、`Allowed Web Origins`を設定\n1. `docker-compose up` （down すると ngrok のアドレスが変わり、auth0 の設定をやり直さないといけないので注意）\n1. http://YOUR_LOCAL_IP:4040/ を開いて ngrok の https アドレスをクリック表示\n1. frontend が表示される\n1. url をコピー\n\n### .env の設定\n\n| AUTH0_DOMAIN           | AUTH0_CLIENT_ID           |\n| ---------------------- | ------------------------- |\n| auth0 の app の Domain | auth0 の app の Client ID |\n\n![](https://i.gyazo.com/aa82a4cb4439c5a4cd736508679cd2d4.png)\n\n## auth0 の設定\n\n| Allowed Callback URLs              | Allowed Logout URLs | Allowed Web Origins |\n| ---------------------------------- | ------------------- | ------------------- |\n| https://...ngrok.io/auth0/callback | https://...ngrok.io | https://...ngrok.io |\n\n![](https://i.gyazo.com/86cc9d4769c1c9e801f1698a5876d98d.png)\n\n## メールアドレス登録でのログイン\n\n1. frontend の login ボタンで auth0 のダイアログが表示されれば一旦は OK\n1. sign up でとりあえずメールアドレス登録でログインしてみる\n1. /users が開けば OK\n1. リロードしてみる\n1. 引き続きログインが出来ていれば OK\n\n## Google の設定\n\nここがややこしい。Google でガチャガチャ設定して Google の`Client ID`、`Client Secret`を作り、`Admin SDK`を有効にしておいて、auth0 の Google connection に Google の`Client ID`、`Client Secret`を設定する流れ。\n\n1. auth0 へログインする\n1. https://auth0.com/docs/connections/social/google を開く\n1. 手順が書いてあるが、一応説明\n1. https://console.developers.google.com/ にログインする\n1. プロジェクトがないならまず作る\n1. OAuth 同意画面へ行く\n1. 承認済みドメインへ`auth0.com`を入れて保存\n1. 認証情報で OAuth クライアント ID 新規作成\n1. ウェブ アプリケーションを選択\n1. 承認済みの JavaScript 生成元、承認済みのリダイレクト URI を https://auth0.com/docs/connections/social/google に表示されているとおりに入力\n1. ID とシークレットが表示されるのでコピー\n1. 念のために作成されたクライアント ID をクリックして内容確認（意外と承認済みの JavaScript 生成元 | 承認済みのリダイレクト URI どっちかが無かったりする）\n1. ライブラリに行って、`admin`と検索して`Admin SDK`を有効にする\n1. auth0 に行く\n1. connections で google をクリックして表示\n1. `Client ID`、`Client Secret`が入力出来るので OAuth クライアント ID 作成時に出来たものを入れる\n1. TRY ボタンで試してみて、google のログインが出たら OK\n1. frontend に行って、google アカウント（誰のでも）でログインしてみる\n1. ログイン後、リロードしてもログイン状態なら成功\n\n### https://auth0.com/docs/connections/social/google\n\n| 承認済みの JavaScript 生成元  | 承認済みのリダイレクト URI |\n| ----------------------------- | -------------------------- |\n| Authorized JavaScript origins | Authorized redirect URIs   |\n\n### OAuth 同意画面（autho0.com 追加）\n\n![](https://i.gyazo.com/d88d8e2adebfc68b5d4aefc39416b889.png)\n\n### ウェブアプリケーションで ID の作成\n\n![](https://i.gyazo.com/5da25c876796232904df82f194470044.png)\n\n### 出来たクライアント ID を開いた所\n\n![](https://i.gyazo.com/4e7b1fefdd395da00dddf89693bd8f62.png)\n\n### Admin SDK の検索\n\n![](https://i.gyazo.com/a1d10849edccf230e6f452bb5b96b5fc.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub0013%2Fnextjs-auth0-google","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub0013%2Fnextjs-auth0-google","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub0013%2Fnextjs-auth0-google/lists"}