@@ -2,11 +2,8 @@ import jwt from "jsonwebtoken";
22import type { NextAuthConfig } from "next-auth" ;
33// eslint-disable-next-line @typescript-eslint/no-unused-vars
44import type { JWT } from "next-auth/jwt" ;
5- import github from "next-auth/providers/github" ;
6- import keycloak from "next-auth/providers/keycloak" ;
7- import nodemailer from "next-auth/providers/nodemailer" ;
85import type { PayloadAuthjsUser } from "payload-authjs" ;
9- import type { User as PayloadUser } from "./payload-types" ;
6+ import type { User as PayloadUser } from ".. /payload-types" ;
107
118declare module "next-auth" {
129 // eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -27,68 +24,16 @@ declare module "next-auth/jwt" {
2724 > { }
2825}
2926
27+ export const SESSION_STRATEGY : NonNullable < NonNullable < NextAuthConfig [ "session" ] > [ "strategy" ] > =
28+ "jwt" ;
29+
3030export const authConfig : NextAuthConfig = {
3131 theme : { logo : "https://authjs.dev/img/logo-sm.png" } ,
32- providers : [
33- github ( {
34- allowDangerousEmailAccountLinking : true ,
35- /**
36- * Add additional fields to the user on first sign in
37- */
38- profile ( profile ) {
39- return {
40- // Default fields (@see https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/github.ts#L176)
41- id : profile . id . toString ( ) ,
42- name : profile . name ?? profile . login ,
43- email : profile . email ,
44- image : profile . avatar_url ,
45- // Custom fields
46- additionalUserDatabaseField : `Create by github provider profile callback at ${ new Date ( ) . toISOString ( ) } ` ,
47- } ;
48- } ,
49- account ( tokens ) {
50- return {
51- ...tokens ,
52- additionalAccountDatabaseField : `Create by github provider profile callback at ${ new Date ( ) . toISOString ( ) } ` ,
53- } ;
54- } ,
55- } ) ,
56- keycloak ( {
57- allowDangerousEmailAccountLinking : true ,
58- /**
59- * Add additional fields to the user on first sign in
60- */
61- profile ( profile ) {
62- return {
63- // Default fields
64- id : profile . sub ,
65- name : profile . name ,
66- email : profile . email ,
67- image : profile . picture ,
68- // Custom fields
69- locale : profile . locale ,
70- additionalUserDatabaseField : `Create by keycloak provider profile callback at ${ new Date ( ) . toISOString ( ) } ` ,
71- } ;
72- } ,
73- account ( tokens ) {
74- return {
75- ...tokens ,
76- additionalAccountDatabaseField : `Create by keycloak provider profile callback at ${ new Date ( ) . toISOString ( ) } ` ,
77- } ;
78- } ,
79- } ) ,
80- nodemailer ( {
81- server : process . env . EMAIL_SERVER ,
82- from : process . env . EMAIL_FROM ,
83- sendVerificationRequest : ( { url } ) => {
84- console . log ( "nodemailer:" , url ) ;
85- } ,
86- } ) ,
87- ] ,
32+ providers : [ ] ,
8833 session : {
89- strategy : "jwt" ,
90- // maxAge: 60 * 2 + 30 , // 2.5 minutes
91- // updateAge: 60, // 1 minute
34+ strategy : SESSION_STRATEGY ,
35+ maxAge : 60 * 15 , // 15 minutes
36+ updateAge : 60 , // 1 minute
9237 } ,
9338 callbacks : {
9439 jwt : ( { token, user, account, trigger } ) => {
@@ -164,8 +109,17 @@ export const authConfig: NextAuthConfig = {
164109 return session ;
165110 } ,
166111 authorized : ( { auth } ) => {
167- // Logged in users are authenticated, otherwise redirect to login page
168- return ! ! auth ;
112+ // User is authenticated
113+ if ( ! auth ?. user ) {
114+ return false ;
115+ }
116+
117+ // Session in not expired
118+ if ( new Date ( ) >= new Date ( auth . expires ) ) {
119+ return false ;
120+ }
121+
122+ return true ;
169123 } ,
170124 } ,
171125} ;
0 commit comments