<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced sign-in error handling with specific messages for different error types. - Implemented IP-based restrictions for authentication and publishing actions. - **Bug Fixes** - Updated the retrieval of user session information to improve reliability. - **Documentation** - Updated usage instructions for `getServerSession` to reflect the new authentication options. - **Refactor** - Replaced direct usage of `authOptions` with a new function `getAuthOptions` to dynamically generate authentication options. - Improved IP address extraction logic to handle various header formats. - **Chores** - Added a new `BannedIp` model to the database schema for managing IP-based restrictions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
38 lines
830 B
TypeScript
38 lines
830 B
TypeScript
import { GetServerSidePropsContext } from 'next'
|
|
import { getServerSession } from 'next-auth'
|
|
import { getAuthOptions } from './api/auth/[...nextauth]'
|
|
|
|
export default function Page() {
|
|
return null
|
|
}
|
|
|
|
export const getServerSideProps = async (
|
|
context: GetServerSidePropsContext
|
|
) => {
|
|
const session = await getServerSession(
|
|
context.req,
|
|
context.res,
|
|
getAuthOptions({})
|
|
)
|
|
if (!session?.user) {
|
|
return {
|
|
redirect: {
|
|
permanent: false,
|
|
destination:
|
|
context.locale !== context.defaultLocale
|
|
? `/${context.locale}/signin`
|
|
: '/signin',
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
redirect: {
|
|
permanent: false,
|
|
destination:
|
|
context.locale !== context.defaultLocale
|
|
? `/${context.locale}/typebots`
|
|
: '/typebots',
|
|
},
|
|
}
|
|
}
|