Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Allow to disable default password log in after SSO … #413

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/web/components/signin/CredentialsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ export default function CredentialsForm() {
<SignIn />
</TabsContent>
<TabsContent value="signup">
{clientConfig.auth.disableSignups ? (
{clientConfig.auth.disableSignups ||
clientConfig.auth.disablePasswordSignups ? (
<p className="text-center">Signups are currently disabled.</p>
) : (
<SignUp />
Expand Down
1 change: 1 addition & 0 deletions apps/web/lib/clientConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ClientConfigCtx = createContext<ClientConfig>({
demoMode: undefined,
auth: {
disableSignups: false,
disablePasswordSignups: false,
},
inference: {
inferredTagLang: "english",
Expand Down
1 change: 1 addition & 0 deletions docs/docs/03-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ When setting up OAuth, the allowed redirect URLs configured at the provider shou
| Name | Required | Default | Description |
| ------------------------------------------- | -------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DISABLE_SIGNUPS | No | false | If enabled, no new signups will be allowed and the signup button will be disabled in the UI |
| DISABLE_PASSWORD_SIGNUPS | No | false | If enabled, only signups using OAuth are allowed and the signup button for a local account will be disabled in the UI |
| OAUTH_WELLKNOWN_URL | No | Not set | The "wellknown Url" for openid-configuration as provided by the OAuth provider |
| OAUTH_CLIENT_SECRET | No | Not set | The "Client Secret" as provided by the OAuth provider |
| OAUTH_CLIENT_ID | No | Not set | The "Client ID" as provided by the OAuth provider |
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const stringBool = (defaultValue: string) =>
const allEnv = z.object({
API_URL: z.string().url().default("http://localhost:3000"),
DISABLE_SIGNUPS: stringBool("false"),
DISABLE_PASSWORD_SIGNUPS: stringBool("false"),
OAUTH_ALLOW_DANGEROUS_EMAIL_ACCOUNT_LINKING: stringBool("false"),
OAUTH_WELLKNOWN_URL: z.string().url().optional(),
OAUTH_CLIENT_SECRET: z.string().optional(),
Expand Down Expand Up @@ -53,6 +54,7 @@ const serverConfigSchema = allEnv.transform((val) => {
apiUrl: val.API_URL,
auth: {
disableSignups: val.DISABLE_SIGNUPS,
disablePasswordSignups: val.DISABLE_PASSWORD_SIGNUPS,
oauth: {
allowDangerousEmailAccountLinking:
val.OAUTH_ALLOW_DANGEROUS_EMAIL_ACCOUNT_LINKING,
Expand Down Expand Up @@ -112,6 +114,7 @@ export const clientConfig = {
demoMode: serverConfig.demoMode,
auth: {
disableSignups: serverConfig.auth.disableSignups,
disablePasswordSignups: serverConfig.auth.disablePasswordSignups,
},
inference: {
inferredTagLang: serverConfig.inference.inferredTagLang,
Expand Down
10 changes: 8 additions & 2 deletions packages/trpc/routers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ export const usersAppRouter = router({
}),
)
.mutation(async ({ input, ctx }) => {
if (serverConfig.auth.disableSignups) {
if (
serverConfig.auth.disableSignups ||
serverConfig.auth.disablePasswordSignups
) {
const errorMessage = serverConfig.auth.disablePasswordSignups
? "Local Signups are disabled in the server config. Use OAuth instead!"
: "Signups are disabled in server config";
throw new TRPCError({
code: "FORBIDDEN",
message: "Signups are disabled in server config",
message: errorMessage,
});
}
// TODO: This is racy, but that's probably fine.
Expand Down
Loading