1
0
Fork 0

refactor(auth): use google provider

This commit is contained in:
Vojtěch Mareš 2023-06-26 23:09:18 +02:00
parent b91d83a5d7
commit ebeabbcdbf
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
3 changed files with 13 additions and 11 deletions

View file

@ -20,6 +20,6 @@ DATABASE_URL="postgresql://username:password@localhost:5432/database"
# NEXTAUTH_SECRET="" # NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_URL="http://localhost:3000"
# Next Auth Discord Provider # Next Auth Google Provider
DISCORD_CLIENT_ID="" GOOGLE_CLIENT_ID=""
DISCORD_CLIENT_SECRET="" GOOGLE_CLIENT_SECRET=""

View file

@ -21,8 +21,8 @@ export const env = createEnv({
process.env.VERCEL ? z.string().min(1) : z.string().url(), process.env.VERCEL ? z.string().min(1) : z.string().url(),
), ),
// Add `.min(1) on ID and SECRET if you want to make sure they're not empty // Add `.min(1) on ID and SECRET if you want to make sure they're not empty
DISCORD_CLIENT_ID: z.string(), GOOGLE_CLIENT_ID: z.string(),
DISCORD_CLIENT_SECRET: z.string(), GOOGLE_CLIENT_SECRET: z.string(),
}, },
/** /**
@ -43,8 +43,8 @@ export const env = createEnv({
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET, NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL, NEXTAUTH_URL: process.env.NEXTAUTH_URL,
DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID, GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
DISCORD_CLIENT_SECRET: process.env.DISCORD_CLIENT_SECRET, GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
}, },
/** /**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.

View file

@ -5,7 +5,7 @@ import {
type NextAuthOptions, type NextAuthOptions,
type DefaultSession, type DefaultSession,
} from "next-auth"; } from "next-auth";
import DiscordProvider from "next-auth/providers/discord"; import GoogleProvider from "next-auth/providers/google";
import { env } from "~/env.mjs"; import { env } from "~/env.mjs";
import { prisma } from "~/server/db"; import { prisma } from "~/server/db";
@ -42,14 +42,16 @@ export const authOptions: NextAuthOptions = {
user: { user: {
...session.user, ...session.user,
id: user.id, id: user.id,
email: user.email,
image: user.image,
}, },
}), }),
}, },
adapter: PrismaAdapter(prisma), adapter: PrismaAdapter(prisma),
providers: [ providers: [
DiscordProvider({ GoogleProvider({
clientId: env.DISCORD_CLIENT_ID, clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET, clientSecret: env.GOOGLE_CLIENT_SECRET,
}), }),
/** /**
* ...add more providers here. * ...add more providers here.