-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export { auth as middleware } from "@/server/auth"; | ||
import NextAuth from "next-auth"; | ||
import authConfig from "./server/auth/middleware-config"; | ||
|
||
export const { auth: middleware } = NextAuth(authConfig) | ||
|
||
export const config = { matcher: ["/process", "/settings", "/", "/user"] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NextAuthConfig, Session } from "next-auth"; | ||
import { JWT } from "next-auth/jwt"; | ||
import Credentials from "next-auth/providers/credentials"; | ||
|
||
// TODO: Currently next.js middleware only supports edge runtime | ||
// This can be removed once next.js provides a option to switch to node.js runtime | ||
export default { | ||
pages: { | ||
signIn: "/login", | ||
error: "/login", | ||
}, | ||
providers: [Credentials], | ||
callbacks: { | ||
async jwt({ token, account, user }) { | ||
if (account && account.access_token) token.accessToken = account.access_token; | ||
|
||
if (user) { | ||
token.acl = user.acl; | ||
token.oauth2 = user.oauth2; | ||
if (user.id) token.id = user.id; | ||
} | ||
return token; | ||
}, | ||
async session({ session, token }: { session: Session; token: JWT }) { | ||
// Send properties to the client, like an access_token and user id from a provider. | ||
session.accessToken = token.accessToken; | ||
session.user.id = token.id; | ||
session.user.acl = token.acl; | ||
session.user.oauth2 = token.oauth2; | ||
|
||
return session; | ||
}, | ||
async authorized({ auth }) { | ||
return !!auth?.user && !!auth.user.id; | ||
}, | ||
}, | ||
} satisfies NextAuthConfig; |