feat(auth): limit output in session endpoint
This commit is contained in:
@@ -104,7 +104,7 @@ const curityProvider = {
|
|||||||
},
|
},
|
||||||
} satisfies OIDCConfig<User>
|
} satisfies OIDCConfig<User>
|
||||||
|
|
||||||
export const config = {
|
const baseConfig = {
|
||||||
basePath: "/api/web/auth",
|
basePath: "/api/web/auth",
|
||||||
debug: env.NEXTAUTH_DEBUG,
|
debug: env.NEXTAUTH_DEBUG,
|
||||||
providers: [curityProvider],
|
providers: [curityProvider],
|
||||||
@@ -122,7 +122,10 @@ export const config = {
|
|||||||
if (session.user) {
|
if (session.user) {
|
||||||
return {
|
return {
|
||||||
...session,
|
...session,
|
||||||
token,
|
token: {
|
||||||
|
expires_at: token.expires_at,
|
||||||
|
error: token.error,
|
||||||
|
},
|
||||||
user: {
|
user: {
|
||||||
...session.user,
|
...session.user,
|
||||||
id: token.sub,
|
id: token.sub,
|
||||||
@@ -160,7 +163,7 @@ export const config = {
|
|||||||
console.log(`[auth] URL denied, returning base URL: ${baseUrl}`)
|
console.log(`[auth] URL denied, returning base URL: ${baseUrl}`)
|
||||||
return baseUrl
|
return baseUrl
|
||||||
},
|
},
|
||||||
async authorized({ auth, request }) {
|
async authorized() {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
async jwt({ account, session, token, trigger, user, profile }) {
|
async jwt({ account, session, token, trigger, user, profile }) {
|
||||||
@@ -223,9 +226,32 @@ export const config = {
|
|||||||
// },
|
// },
|
||||||
} satisfies NextAuthConfig
|
} satisfies NextAuthConfig
|
||||||
|
|
||||||
|
const serverConfig = {
|
||||||
|
...baseConfig,
|
||||||
|
callbacks: {
|
||||||
|
...baseConfig.callbacks,
|
||||||
|
async session({ session, token }) {
|
||||||
|
session.error = token.error
|
||||||
|
if (session.user) {
|
||||||
|
return {
|
||||||
|
...session,
|
||||||
|
token,
|
||||||
|
user: {
|
||||||
|
...session.user,
|
||||||
|
id: token.sub,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return session
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies NextAuthConfig
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
handlers: { GET, POST },
|
handlers: { GET, POST },
|
||||||
auth,
|
|
||||||
signIn,
|
signIn,
|
||||||
signOut,
|
signOut,
|
||||||
} = NextAuth(config)
|
} = NextAuth(baseConfig)
|
||||||
|
|
||||||
|
export const { auth } = NextAuth(serverConfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user