mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
added allow localhost
This commit is contained in:
parent
9bdd34e1e7
commit
3737f68e07
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { IconButton, List, ListItem, ListDivider, Input, FormControl, FormLabel } from "@mui/joy";
|
||||
import { IconButton, List, ListItem, ListDivider, Input, FormControl, FormLabel, Checkbox, Typography, Box } from "@mui/joy";
|
||||
import React, { use, useState } from "react";
|
||||
import { Paragraph } from "@/components/paragraph";
|
||||
import { Icon } from "@/components/icon";
|
||||
@ -9,6 +9,7 @@ import { AsyncButton } from "@/components/async-button";
|
||||
import { useStrictMemo } from "@stackframe/stack-shared/src/hooks/use-strict-memo";
|
||||
import { SimpleCard } from "@/components/simple-card";
|
||||
import { useAdminApp } from "../../useAdminInterface";
|
||||
import { SmartSwitch } from "@/components/smart-switch";
|
||||
|
||||
export default function UrlsAndCallbacksClient() {
|
||||
const stackAdminApp = useAdminApp();
|
||||
@ -32,47 +33,59 @@ export default function UrlsAndCallbacksClient() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Paragraph h1>
|
||||
Domains and Handler
|
||||
</Paragraph>
|
||||
<SimpleCard title="Your Domains and Handler">
|
||||
<Box sx={{ my: 2 }}>
|
||||
<SmartSwitch
|
||||
checked={project.evaluatedConfig.allowLocalhost}
|
||||
onChange={async (event) => {
|
||||
await stackAdminApp.updateProject({
|
||||
config: {
|
||||
allowLocalhost: event.target.checked,
|
||||
},
|
||||
});
|
||||
setInvalidationCounter(invalidationCounter + 1);
|
||||
}}
|
||||
>
|
||||
<Typography>Allow all localhost callbacks for development</Typography>
|
||||
</SmartSwitch>
|
||||
</Box>
|
||||
|
||||
<SimpleCard title="Allowed Oauth callback URLs">
|
||||
<Paragraph sidenote sx={{ mt: 0 }}>
|
||||
Please put in a list of your domains that you control and run the handler on.
|
||||
</Paragraph>
|
||||
{domains.size >= 0 || (
|
||||
<List
|
||||
variant="soft"
|
||||
sx={{
|
||||
"--List-radius": "9px"
|
||||
}}
|
||||
>
|
||||
{[...domains].map(({ domain }, i) => (
|
||||
<React.Fragment key={domain}>
|
||||
{i !== 0 && <ListDivider />}
|
||||
<ListItem
|
||||
endAction={
|
||||
<IconButton
|
||||
aria-label="Delete"
|
||||
size="sm"
|
||||
color="danger"
|
||||
onClick={() => setDeleteDialogDomain(domain)}
|
||||
>
|
||||
<Icon icon="delete" />
|
||||
</IconButton>
|
||||
}
|
||||
>
|
||||
{domain}
|
||||
</ListItem>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</List>
|
||||
)}
|
||||
|
||||
<List
|
||||
variant="soft"
|
||||
sx={{
|
||||
"--List-radius": "9px"
|
||||
}}
|
||||
>
|
||||
{[...domains].map(({ domain }, i) => (
|
||||
<React.Fragment key={domain}>
|
||||
{i !== 0 && <ListDivider />}
|
||||
<ListItem
|
||||
endAction={
|
||||
<IconButton
|
||||
aria-label="Delete"
|
||||
size="sm"
|
||||
color="danger"
|
||||
onClick={() => setDeleteDialogDomain(domain)}
|
||||
>
|
||||
<Icon icon="delete" />
|
||||
</IconButton>
|
||||
}
|
||||
>
|
||||
{domain}
|
||||
</ListItem>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</List>
|
||||
<AsyncButton
|
||||
onClick={() => setAddNewDialogOpen(true)}
|
||||
variant="plain"
|
||||
variant="soft"
|
||||
color="neutral"
|
||||
sx={{ mt: 3 }}
|
||||
>
|
||||
Add new prefix
|
||||
Add new domain
|
||||
</AsyncButton>
|
||||
</SimpleCard>
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ export default function EnvironmentClient() {
|
||||
}}
|
||||
>
|
||||
<Typography>
|
||||
Enable production mode
|
||||
Enable production mode
|
||||
</Typography>
|
||||
</SmartSwitch>
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@ const putOrGetSchema = yup.object({
|
||||
})
|
||||
).optional(),
|
||||
credentialEnabled: yup.boolean().optional(),
|
||||
allowLocalhost: yup.boolean().optional(),
|
||||
}).optional(),
|
||||
}).nullable(),
|
||||
});
|
||||
@ -47,7 +48,7 @@ const handler = smartRouteHandler(async (req: NextRequest, options: { params: {
|
||||
"x-stack-admin-access-token": adminAccessToken,
|
||||
},
|
||||
body,
|
||||
} = await parseRequest(req, putOrGetSchema);
|
||||
} = await parseRequest(req, putOrGetSchema);
|
||||
|
||||
const { showDisabledOauth, ...update } = body ?? {};
|
||||
|
||||
@ -59,6 +60,8 @@ const handler = smartRouteHandler(async (req: NextRequest, options: { params: {
|
||||
isProductionMode: update.isProductionMode,
|
||||
config: update.config && {
|
||||
domains: update.config.domains,
|
||||
allowLocalhost: update.config.allowLocalhost,
|
||||
credentialEnabled: update.config.credentialEnabled,
|
||||
oauthProviders: update.config.oauthProviders && update.config.oauthProviders.map((provider) => {
|
||||
if (sharedProviders.includes(provider.type as SharedProvider)) {
|
||||
return {
|
||||
@ -86,7 +89,6 @@ const handler = smartRouteHandler(async (req: NextRequest, options: { params: {
|
||||
throw new StatusError(StatusError.BadRequest, "Invalid oauth provider type");
|
||||
}
|
||||
}),
|
||||
credentialEnabled: update.config.credentialEnabled,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -358,14 +358,22 @@ export async function updateProject(
|
||||
}
|
||||
}
|
||||
|
||||
// Update credentialEnabled
|
||||
if (options.config?.credentialEnabled !== undefined) {
|
||||
// Update credentialEnabled
|
||||
transaction.push(prismaClient.projectConfig.update({
|
||||
where: { id: project.config.id },
|
||||
data: { credentialEnabled: options.config.credentialEnabled },
|
||||
}));
|
||||
}
|
||||
|
||||
// Update allowLocalhost
|
||||
if (options.config?.allowLocalhost !== undefined) {
|
||||
transaction.push(prismaClient.projectConfig.update({
|
||||
where: { id: project.config.id },
|
||||
data: { allowLocalhost: options.config.allowLocalhost },
|
||||
}));
|
||||
}
|
||||
|
||||
if (options.isProductionMode !== undefined) {
|
||||
// Update production mode
|
||||
transaction.push(prismaClient.project.update({
|
||||
|
||||
@ -39,6 +39,7 @@ export type ProjectUpdateOptions = Readonly<{
|
||||
}[],
|
||||
oauthProviders?: OauthProviderUpdateOptions[],
|
||||
credentialEnabled?: boolean,
|
||||
allowLocalhost?: boolean,
|
||||
},
|
||||
}>
|
||||
|
||||
@ -131,7 +132,7 @@ export class StackAdminInterface extends StackServerInterface {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(options || {}),
|
||||
body: JSON.stringify(options ?? {}),
|
||||
},
|
||||
null,
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user