Skip to content

Commit

Permalink
add: google & github providers (#1362)
Browse files Browse the repository at this point in the history
* add: google & github providers

* update: remove experimental appDir as no longer needed

* add: condition check for next-auth

---------

Co-authored-by: opacteam <[email protected]>
  • Loading branch information
mikah13 and opacteam authored Oct 18, 2023
1 parent bfa760d commit 046cd02
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
11 changes: 10 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ EMAIL_FROM=
DATABASE_URL='postgresql://'
SHADOW_DATABASE_URL='postgresql://'
# Used to encrypt the NextAuth.js JWT, and to hash email verification tokens. This is the default value for the secret option in NextAuth and Middleware.
NEXTAUTH_SECRET=JWT_SECRET_KEY
NEXTAUTH_SECRET=JWT_SECRET_KEY

# Github NextAuth Credentials
GITHUB_ID=
GITHUB_SECRET=


# Google NextAuth Credentials
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
3 changes: 0 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ const { createSecureHeaders } = require("next-secure-headers");

/** @type {import('next').NextConfig} */
module.exports = {
experimental: {
appDir: true,
},
async headers() {
return [{ source: "/(.*)", headers: createSecureHeaders() }];
},
Expand Down
42 changes: 35 additions & 7 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@ import { PrismaAdapter } from '@next-auth/prisma-adapter';
import * as Prisma from '@prisma/client';
import NextAuth from 'next-auth';
import EmailProvider from 'next-auth/providers/email';
import GithubProvider from 'next-auth/providers/github';
import GoogleProvider from 'next-auth/providers/google';

const prisma = new Prisma.PrismaClient();


// Default option
const providers = [
EmailProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
}),
];

// GitHub Provider
if (process.env.GITHUB_ID && process.env.GITHUB_SECRET) {
providers.push(
GithubProvider({

Check failure on line 23 in pages/api/auth/[...nextauth].ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'OAuthConfig<GithubProfile>' is not assignable to parameter of type 'EmailConfig'.
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
})
);
}

// Google Provider

if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET) {
providers.push(
GoogleProvider({

Check failure on line 34 in pages/api/auth/[...nextauth].ts

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'OAuthConfig<GoogleProfile>' is not assignable to parameter of type 'EmailConfig'.
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
})
);
}

export default NextAuth({
providers: [
EmailProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
}),
],
adapter: PrismaAdapter(prisma),
providers,
adapter: PrismaAdapter(prisma),
});
2 changes: 1 addition & 1 deletion public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* tslint:disable */

/**
* Mock Service Worker (1.2.2).
* Mock Service Worker (1.3.2).
* @see https://github.com/mswjs/msw
* - Please do NOT modify this file.
* - Please do NOT serve this file on production.
Expand Down

0 comments on commit 046cd02

Please sign in to comment.