This commit is contained in:
2022-04-11 11:07:29 +01:00
parent 412b7c15b6
commit 67102497f0
8 changed files with 4266 additions and 2584 deletions
+29 -25
View File
@@ -1,33 +1,37 @@
import NextAuth from "next-auth";
import Providers from "next-auth/providers";
import { Magic } from "@magic-sdk/admin";
const magic = new Magic(process.env.MAGIC_SK);
import { TypeORMLegacyAdapter } from "@next-auth/typeorm-legacy-adapter";
import EmailProvider from "next-auth/providers/email";
import * as entities from "../../../lib/entities";
// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
export default NextAuth({
session: {
jwt: true,
},
pages: {
// override signIn page so we can integrate with Magic
signIn: "/auth/signin",
},
// https://next-auth.js.org/configuration/providers
providers: [
Providers.Credentials({
name: "Magic Link",
credentials: {
didToken: { label: "DID Token", type: "text" },
},
async authorize({ didToken }, req) {
// validate magic DID token
magic.token.validate(didToken);
// fetch user metadata
const metadata = await magic.users.getMetadataByToken(didToken);
// return user info
return { ...metadata };
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
maxAge: 10 * 60, // Magic links are valid for 10 min only
}),
],
adapter: TypeORMLegacyAdapter({
type: "mysql",
database:
"mysql://nextAuthAdmin:!Sky9fish1972@77.68.17.157:3306/nextauthDB?synchronise=true",
synchronize: false,
}),
secret: "SuperSecret",
session: {
jwt: true,
pages: {},
theme: "dark",
debug: true,
},
});