create-nicsde-next-app
Version:
A CLI tool to create Next.js applications with custom configurations
46 lines (42 loc) • 1.11 kB
text/typescript
import type { OAuthConfig, OAuthUserConfig } from "next-auth/providers/index"
export interface CustomProfile {
email: string
username: string
family_name: string
website: string
orgId: string
typeId: string
userTypeCode: string
}
export default function CustomProvider<P extends CustomProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
return {
id: "tongji",
name: "Tongji",
type: "oauth",
authorization: {
url: `${process.env.NEXT_PUBLIC_AUTH_TONGJI_URL}/idp/oauth2/authorize`,
params: {
scope: ''
}
},
token: {
url: `${process.env.NEXTAUTH_URL}/api/token`
},
userinfo: `${process.env.NEXT_PUBLIC_AUTH_TONGJI_URL}/idp/oauth2/getUserInfoByBearerAuth`,
async profile(profile) {
const userInfo = {
family_name: profile.family_name,
website: profile.website,
email: profile.email,
orgId: profile.orgId,
username: profile.username,
typeId: profile.typeId,
userTypeCode: profile.userTypeCode,
}
return userInfo;
},
options,
}
}