Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔒 Local Auth Improvements #449

Merged
merged 4 commits into from
May 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
🧹 Tidy auth providers
  • Loading branch information
awtkns committed May 7, 2023
commit 2a6a64e3242d2017dfb34965bf57cb8230c78b91
62 changes: 17 additions & 45 deletions src/server/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
import { serverEnv } from "../../env/schema.mjs";
import type {Provider} from "next-auth/providers";
import type {NextAuthOptions} from "next-auth";

/**
* Module augmentation for `next-auth` types
* Allows us to add custom properties to the `session` object
* and keep type safety
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
**/

const getProviders = () => {
const providers: Provider[] = []

if (serverEnv.GOOGLE_CLIENT_ID && serverEnv.GOOGLE_CLIENT_SECRET) {
providers.push(
GoogleProvider({
clientId: serverEnv.GOOGLE_CLIENT_ID,
clientSecret: serverEnv.GOOGLE_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true,
}),
)
}

if (serverEnv.GITHUB_CLIENT_ID && serverEnv.GITHUB_CLIENT_SECRET) {
providers.push(
GithubProvider({
clientId: serverEnv.GITHUB_CLIENT_ID,
clientSecret: serverEnv.GITHUB_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true,
}),
)
}

if (serverEnv.DISCORD_CLIENT_ID && serverEnv.DISCORD_CLIENT_SECRET) {
providers.push(
GithubProvider({
clientId: serverEnv.DISCORD_CLIENT_ID,
clientSecret: serverEnv.DISCORD_CLIENT_ID,
allowDangerousEmailAccountLinking: true,
}),
)
}

return providers;
}

export const authOptions: NextAuthOptions = {
providers: getProviders(),
providers: [
GoogleProvider({
clientId: serverEnv.GOOGLE_CLIENT_ID ?? "",
clientSecret: serverEnv.GOOGLE_CLIENT_SECRET ?? "",
allowDangerousEmailAccountLinking: true,
}),
GithubProvider({
clientId: serverEnv.GITHUB_CLIENT_ID ?? "",
clientSecret: serverEnv.GITHUB_CLIENT_SECRET ?? "",
allowDangerousEmailAccountLinking: true,
}),
GithubProvider({
clientId: serverEnv.DISCORD_CLIENT_ID ?? "",
clientSecret: serverEnv.DISCORD_CLIENT_ID ?? "",
allowDangerousEmailAccountLinking: true,
}),
],
};