forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: refactor the auth (lobehub#2043)
* ♻️ refactor: refactor the auth code * ♻️ refactor: refactor the auth code * ♻️ refactor: refactor the auth code * ♻️ refactor: refactor the auth code * 🎨 refactor: improve code
- Loading branch information
Showing
27 changed files
with
133 additions
and
44 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,3 @@ | ||
export { GET, POST } from '../next-auth'; | ||
export { GET, POST } from '@/libs/next-auth'; | ||
|
||
export const runtime = 'edge'; // optional |
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
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
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,71 @@ | ||
/* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */ | ||
|
||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace NodeJS { | ||
interface ProcessEnv { | ||
ENABLE_OAUTH_SSO?: string; | ||
SSO_PROVIDERS?: string; | ||
|
||
AUTH0_CLIENT_ID?: string; | ||
AUTH0_CLIENT_SECRET?: string; | ||
AUTH0_ISSUER?: string; | ||
|
||
// Github | ||
GITHUB_CLIENT_ID?: string; | ||
GITHUB_CLIENT_SECRET?: string; | ||
|
||
// Azure AD | ||
AZURE_AD_CLIENT_ID?: string; | ||
AZURE_AD_CLIENT_SECRET?: string; | ||
AZURE_AD_TENANT_ID?: string; | ||
|
||
// AUTHENTIK | ||
AUTHENTIK_CLIENT_ID?: string; | ||
AUTHENTIK_CLIENT_SECRET?: string; | ||
AUTHENTIK_ISSUER?: string; | ||
|
||
// ZITADEL | ||
ZITADEL_CLIENT_ID?: string; | ||
ZITADEL_CLIENT_SECRET?: string; | ||
ZITADEL_ISSUER?: string; | ||
NEXTAUTH_SECRET?: string; | ||
} | ||
} | ||
} | ||
|
||
export const getAuthConfig = () => { | ||
if (typeof process === 'undefined') { | ||
throw new Error('[Server Config] you are importing a server-only module outside of server'); | ||
} | ||
|
||
return { | ||
ENABLE_OAUTH_SSO: !!process.env.ENABLE_OAUTH_SSO, | ||
SSO_PROVIDERS: process.env.SSO_PROVIDERS || 'auth0', | ||
|
||
// Auth0 | ||
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || '', | ||
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET || '', | ||
AUTH0_ISSUER: process.env.AUTH0_ISSUER || '', | ||
|
||
// Github | ||
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID || '', | ||
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET || '', | ||
|
||
// Azure AD | ||
AZURE_AD_CLIENT_ID: process.env.AZURE_AD_CLIENT_ID || '', | ||
AZURE_AD_CLIENT_SECRET: process.env.AZURE_AD_CLIENT_SECRET || '', | ||
AZURE_AD_TENANT_ID: process.env.AZURE_AD_TENANT_ID || '', | ||
|
||
// AUTHENTIK | ||
AUTHENTIK_CLIENT_ID: process.env.AUTHENTIK_CLIENT_ID || '', | ||
AUTHENTIK_CLIENT_SECRET: process.env.AUTHENTIK_CLIENT_SECRET || '', | ||
AUTHENTIK_ISSUER: process.env.AUTHENTIK_ISSUER || '', | ||
|
||
// ZITADEL | ||
ZITADEL_CLIENT_ID: process.env.ZITADEL_CLIENT_ID || '', | ||
ZITADEL_CLIENT_SECRET: process.env.ZITADEL_CLIENT_SECRET || '', | ||
ZITADEL_ISSUER: process.env.ZITADEL_ISSUER || '', | ||
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET || '', | ||
}; | ||
}; |
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,10 @@ | ||
import { SessionProvider } from 'next-auth/react'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
import { API_ENDPOINTS } from '@/services/_url'; | ||
|
||
const NextAuth = ({ children }: PropsWithChildren) => { | ||
return <SessionProvider basePath={API_ENDPOINTS.oauth}>{children}</SessionProvider>; | ||
}; | ||
|
||
export default NextAuth; |
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,16 +1,12 @@ | ||
import { SessionProvider } from 'next-auth/react'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
import { getServerConfig } from '@/config/server'; | ||
import { API_ENDPOINTS } from '@/services/_url'; | ||
|
||
import NextAuth from './NextAuth'; | ||
|
||
const { ENABLE_OAUTH_SSO = false } = getServerConfig(); | ||
|
||
const AuthProvider = ({ children }: PropsWithChildren) => | ||
ENABLE_OAUTH_SSO ? ( | ||
<SessionProvider basePath={API_ENDPOINTS.oauth}>{children}</SessionProvider> | ||
) : ( | ||
children | ||
); | ||
ENABLE_OAUTH_SSO ? <NextAuth>{children}</NextAuth> : children; | ||
|
||
export default AuthProvider; |
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,11 @@ | ||
import { memo } from 'react'; | ||
|
||
import AvatarWithUpload from '@/features/AvatarWithUpload'; | ||
|
||
const Avatar = memo(() => { | ||
return <AvatarWithUpload id={'avatar'} />; | ||
}); | ||
|
||
Avatar.displayName = 'Avatar'; | ||
|
||
export default Avatar; |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
src/layout/GlobalLayout/Mobile/Client.tsx → src/layout/DefaultLayout/Mobile/index.tsx
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,2 @@ | ||
export { default as DefaultLayoutDesktop } from './Desktop'; | ||
export { default as DefaultLayoutMobile } from './Mobile'; |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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