Skip to content

Commit

Permalink
feat: simplify auth using credentials instead of oauth provider (#38)
Browse files Browse the repository at this point in the history
* feat: simplify auth using credentials instead of oauth provider

* update comment
  • Loading branch information
subfuzion authored Mar 23, 2023
1 parent 16ddd8e commit 8ac1aa2
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import NextAuth, { AuthOptions } from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import assert from 'node:assert';
import NextAuth, {AuthOptions} from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

assert(process.env.GOOGLE_CLIENT_ID);
assert(process.env.GOOGLE_CLIENT_SECRET);

export const authOptions: AuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
CredentialsProvider({
credentials: {
username: {label: "Username", type: "text", placeholder: "username"},
email: {label: "Email", type: "text", placeholder: "email"},
// password: {label: "Password", type: "password"}
},
async authorize(credentials) {
if (!credentials) {
// Display an error will be displayed advising the user to check
// their details.
return null;
}

const username = credentials.username;
const email = credentials.email;
const user = {id: "1", name: username, email: email};

if (user) {
return user;
} else {
// Display an error will be displayed advising the user to check
// their details.
return null;
// Or reject this callback with an Error to send the user to the error
// page with the error message as a query parameter
}
}
}),
],
};
Expand Down

0 comments on commit 8ac1aa2

Please sign in to comment.