diff --git a/src/lib/config/Config.ts b/src/lib/config/Config.ts index ac9bc6d..cb52c31 100644 --- a/src/lib/config/Config.ts +++ b/src/lib/config/Config.ts @@ -123,6 +123,8 @@ export interface ConfigFeatures { } export interface ConfigOAuth { + bypass_local_login: boolean; + github_client_id?: string; github_client_secret?: string; diff --git a/src/lib/config/readConfig.ts b/src/lib/config/readConfig.ts index 7a81d10..f2e94f0 100644 --- a/src/lib/config/readConfig.ts +++ b/src/lib/config/readConfig.ts @@ -136,6 +136,8 @@ export default function readConfig() { map('DISCORD_SHORTEN_EMBED_THUMBNAIL', 'boolean', 'discord.shorten.embed.thumbnail'), map('DISCORD_SHORTEN_EMBED_TIMESTAMP', 'boolean', 'discord.shorten.embed.timestamp'), + map('OAUTH_BYPASS_LOCAL_LOGIN', 'boolean', 'oauth.bypass_local_login'), + map('OAUTH_GITHUB_CLIENT_ID', 'string', 'oauth.github_client_id'), map('OAUTH_GITHUB_CLIENT_SECRET', 'string', 'oauth.github_client_secret'), diff --git a/src/lib/config/validateConfig.ts b/src/lib/config/validateConfig.ts index 272d47e..cbc0f99 100644 --- a/src/lib/config/validateConfig.ts +++ b/src/lib/config/validateConfig.ts @@ -168,6 +168,8 @@ const validator = s.object({ .nullish.default(null), oauth: s .object({ + bypass_local_login: s.boolean.default(false), + github_client_id: s.string.nullable.default(null), github_client_secret: s.string.nullable.default(null), diff --git a/src/lib/middleware/getServerSideProps.ts b/src/lib/middleware/getServerSideProps.ts index 9f2353f..44bf4f6 100644 --- a/src/lib/middleware/getServerSideProps.ts +++ b/src/lib/middleware/getServerSideProps.ts @@ -16,6 +16,7 @@ export type ServerSideProps = { user_registration: boolean; oauth_registration: boolean; oauth_providers: string; + bypass_local_login: boolean; chunks_size: number; max_size: number; totp_enabled: boolean; @@ -60,6 +61,7 @@ export const getServerSideProps: GetServerSideProps = async (ct user_registration: config.features.user_registration, oauth_registration: config.features.oauth_registration, oauth_providers: JSON.stringify(oauth_providers), + bypass_local_login: config.oauth.bypass_local_login, chunks_size: config.chunks.chunks_size, max_size: config.chunks.max_size, totp_enabled: config.mfa.totp_enabled, diff --git a/src/pages/auth/login.tsx b/src/pages/auth/login.tsx index 7106ab2..5203b90 100644 --- a/src/pages/auth/login.tsx +++ b/src/pages/auth/login.tsx @@ -22,7 +22,13 @@ import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; export { getServerSideProps } from 'middleware/getServerSideProps'; -export default function Login({ title, user_registration, oauth_registration, oauth_providers: unparsed }) { +export default function Login({ + title, + user_registration, + oauth_registration, + bypass_local_login, + oauth_providers: unparsed, +}) { const router = useRouter(); // totp modal @@ -34,6 +40,9 @@ export default function Login({ title, user_registration, oauth_registration, oa const oauth_providers = JSON.parse(unparsed); + const show_local_login = + router.query.local === 'true' || !(bypass_local_login && oauth_providers?.length > 0); + const icons = { GitHub: IconBrandGithub, Discord: IconBrandDiscordFilled, @@ -99,6 +108,12 @@ export default function Login({ title, user_registration, oauth_registration, oa useEffect(() => { (async () => { + // if the user includes `local=true` as a query param, show the login form + // otherwise, redirect to the oauth login if there is only one registered provider + if (bypass_local_login && oauth_providers?.length === 1 && router.query.local !== 'true') { + await router.push(oauth_providers[0].url); + } + const a = await fetch('/api/user'); if (a.ok) await router.push('/dashboard'); })(); @@ -152,7 +167,7 @@ export default function Login({ title, user_registration, oauth_registration, oa
- {title} + {bypass_local_login ? ' Login to Zipline with' : 'Zipline'} {oauth_registration && ( @@ -165,7 +180,7 @@ export default function Login({ title, user_registration, oauth_registration, oa variant='outline' radius='md' fullWidth - leftIcon={} + leftIcon={} my='xs' component={Link} href={url} @@ -174,41 +189,42 @@ export default function Login({ title, user_registration, oauth_registration, oa ))} - - + {show_local_login && } )} -
onSubmit(v))}> - - + {show_local_login && ( + onSubmit(v))}> + + - - {user_registration && ( - - Don't have an account? Register - - )} + + {user_registration && ( + + Don't have an account? Register + + )} - - - + + + + )}