IntegrationsSSO and Google Auth
PullTheCode usesNextAuthto authenticate users. You can configure it in thesrc/app/api/auth/[...nextauth]/route.ts
file.
Setup
- Make sure that you performed the following changes to the
.env
file:NEXT_PUBLIC_WEBSITE_NAME=YOUR_WEBSITE_NAMENEXT_PUBLIC_WEBSITE_URL=http://localhost:3000NEXTAUTH_SECRET=RANDOM_ALPHANUMERIC_STRING_AT_LEAST_32_CHARACTERS_LONGPOSTGRES_PRISMA_URL=file:./dev.db - Create a new project in theGoogle Console
- Go to [APIs & Services] > Credentials
- Click [Configure Consent Screen]
- Fill the form. You will be asked to provide a support email address, a product name, and the links for your privacy policy and terms of service, which you can generate with ChatGPT. Add userinfo.email & userinfo.profile to scope and add yourself as a test user. Confirm and save.
- Go to [Credentials] > [+ Create Credentials] > [Oauth Client ID]
- Select [Web Application]. Add
http://localhost:3000
andhttps://your-website
to Authorized JavaScript origins. Addhttp://localhost:3000/api/auth/callback/google
andhttps://your-website.com/api/auth/callback/google
to Authorized JavaScript origins. Click [Create] - Copy paste the Client ID in
AUTH_GOOGLE_ID
and Client Secret inAUTH_GOOGLE_SECRET
to the.env
file. - Go to [Oauth Consent Screen] > [Publish App], and submit for verification. Click [Prepare for verification] and fill the required information. Google will email you and you will have to reply to start the process. Your domain needs to be verified withGoogle Search Console. While you can already login with Google on localhost without issues, on production, it will work too but show a warning until you are verified (it usually takes a few days).
Create a checkout
From the front-end, use the ButtonCallToAction
to automatically create a checkout session (one-time payment or subscription)
View the /src/app/api/stripe/route.ts
route file to see how the various cases are handled.