mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +00:00
feat: add option to disable continue screen
This commit is contained in:
13
cmd/root.go
13
cmd/root.go
@@ -87,11 +87,12 @@ var rootCmd = &cobra.Command{
|
|||||||
|
|
||||||
// Create API
|
// Create API
|
||||||
api := api.NewAPI(types.APIConfig{
|
api := api.NewAPI(types.APIConfig{
|
||||||
Port: config.Port,
|
Port: config.Port,
|
||||||
Address: config.Address,
|
Address: config.Address,
|
||||||
Secret: config.Secret,
|
Secret: config.Secret,
|
||||||
AppURL: config.AppURL,
|
AppURL: config.AppURL,
|
||||||
CookieSecure: config.CookieSecure,
|
CookieSecure: config.CookieSecure,
|
||||||
|
DisableContinue: config.DisableContinue,
|
||||||
}, hooks, auth, providers)
|
}, hooks, auth, providers)
|
||||||
|
|
||||||
// Setup routes
|
// Setup routes
|
||||||
@@ -138,6 +139,7 @@ func init() {
|
|||||||
rootCmd.Flags().String("generic-auth-url", "", "Generic OAuth auth URL.")
|
rootCmd.Flags().String("generic-auth-url", "", "Generic OAuth auth URL.")
|
||||||
rootCmd.Flags().String("generic-token-url", "", "Generic OAuth token URL.")
|
rootCmd.Flags().String("generic-token-url", "", "Generic OAuth token URL.")
|
||||||
rootCmd.Flags().String("generic-user-info-url", "", "Generic OAuth user info URL.")
|
rootCmd.Flags().String("generic-user-info-url", "", "Generic OAuth user info URL.")
|
||||||
|
rootCmd.Flags().Bool("disable-continue", false, "Disable continue screen and redirect to app directly.")
|
||||||
viper.BindEnv("port", "PORT")
|
viper.BindEnv("port", "PORT")
|
||||||
viper.BindEnv("address", "ADDRESS")
|
viper.BindEnv("address", "ADDRESS")
|
||||||
viper.BindEnv("secret", "SECRET")
|
viper.BindEnv("secret", "SECRET")
|
||||||
@@ -155,5 +157,6 @@ func init() {
|
|||||||
viper.BindEnv("generic-auth-url", "GENERIC_AUTH_URL")
|
viper.BindEnv("generic-auth-url", "GENERIC_AUTH_URL")
|
||||||
viper.BindEnv("generic-token-url", "GENERIC_TOKEN_URL")
|
viper.BindEnv("generic-token-url", "GENERIC_TOKEN_URL")
|
||||||
viper.BindEnv("generic-user-info-url", "GENERIC_USER_INFO_URL")
|
viper.BindEnv("generic-user-info-url", "GENERIC_USER_INFO_URL")
|
||||||
|
viper.BindEnv("disable-continue", "DISABLE_CONTINUE")
|
||||||
viper.BindPFlags(rootCmd.Flags())
|
viper.BindPFlags(rootCmd.Flags())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ func (api *API) SetupRoutes() {
|
|||||||
"oauth": false,
|
"oauth": false,
|
||||||
"provider": "",
|
"provider": "",
|
||||||
"configuredProviders": api.Providers.GetConfiguredProviders(),
|
"configuredProviders": api.Providers.GetConfiguredProviders(),
|
||||||
|
"disableContinue": api.Config.DisableContinue,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -220,6 +221,7 @@ func (api *API) SetupRoutes() {
|
|||||||
"oauth": userContext.OAuth,
|
"oauth": userContext.OAuth,
|
||||||
"provider": userContext.Provider,
|
"provider": userContext.Provider,
|
||||||
"configuredProviders": api.Providers.GetConfiguredProviders(),
|
"configuredProviders": api.Providers.GetConfiguredProviders(),
|
||||||
|
"disableContinue": api.Config.DisableContinue,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ type Config struct {
|
|||||||
GenericAuthURL string `mapstructure:"generic-auth-url"`
|
GenericAuthURL string `mapstructure:"generic-auth-url"`
|
||||||
GenericTokenURL string `mapstructure:"generic-token-url"`
|
GenericTokenURL string `mapstructure:"generic-token-url"`
|
||||||
GenericUserInfoURL string `mapstructure:"generic-user-info-url"`
|
GenericUserInfoURL string `mapstructure:"generic-user-info-url"`
|
||||||
|
DisableContinue bool `mapstructure:"disable-continue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserContext struct {
|
type UserContext struct {
|
||||||
@@ -46,11 +47,12 @@ type UserContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type APIConfig struct {
|
type APIConfig struct {
|
||||||
Port int
|
Port int
|
||||||
Address string
|
Address string
|
||||||
Secret string
|
Secret string
|
||||||
AppURL string
|
AppURL string
|
||||||
CookieSecure bool
|
CookieSecure bool
|
||||||
|
DisableContinue bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type OAuthConfig struct {
|
type OAuthConfig struct {
|
||||||
|
|||||||
@@ -9,12 +9,16 @@ export const ContinuePage = () => {
|
|||||||
const params = new URLSearchParams(queryString);
|
const params = new URLSearchParams(queryString);
|
||||||
const redirectUri = params.get("redirect_uri");
|
const redirectUri = params.get("redirect_uri");
|
||||||
|
|
||||||
const { isLoggedIn } = useUserContext();
|
const { isLoggedIn, disableContinue } = useUserContext();
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
return <Navigate to="/login" />;
|
return <Navigate to="/login" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (disableContinue && redirectUri !== "null") {
|
||||||
|
window.location.replace(redirectUri!);
|
||||||
|
}
|
||||||
|
|
||||||
const redirect = () => {
|
const redirect = () => {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: "Redirecting",
|
title: "Redirecting",
|
||||||
|
|||||||
@@ -96,55 +96,70 @@ export const LoginPage = () => {
|
|||||||
<Layout>
|
<Layout>
|
||||||
<Title ta="center">Tinyauth</Title>
|
<Title ta="center">Tinyauth</Title>
|
||||||
<Paper shadow="md" p="xl" mt={30} radius="md" withBorder>
|
<Paper shadow="md" p="xl" mt={30} radius="md" withBorder>
|
||||||
<Text size="lg" fw={500} ta="center">
|
{configuredProviders.length === 0 && (
|
||||||
Welcome back, login with
|
<Text size="lg" mb="md" fw={500} ta="center">
|
||||||
</Text>
|
Welcome back, please login
|
||||||
<Grid mb="md" mt="md" align="center" justify="center">
|
</Text>
|
||||||
{configuredProviders.includes("google") && (
|
)}
|
||||||
<Grid.Col span="content">
|
{configuredProviders.length > 0 && (
|
||||||
<Button
|
<>
|
||||||
radius="xl"
|
<Text size="lg" fw={500} ta="center">
|
||||||
leftSection={<GoogleIcon style={{ width: 14, height: 14 }} />}
|
Welcome back, login with
|
||||||
variant="default"
|
</Text>
|
||||||
onClick={() => loginOAuthMutation.mutate("google")}
|
<Grid mb="md" mt="md" align="center" justify="center">
|
||||||
loading={loginOAuthMutation.isLoading}
|
{configuredProviders.includes("google") && (
|
||||||
>
|
<Grid.Col span="content">
|
||||||
Google
|
<Button
|
||||||
</Button>
|
radius="xl"
|
||||||
</Grid.Col>
|
leftSection={
|
||||||
)}
|
<GoogleIcon style={{ width: 14, height: 14 }} />
|
||||||
{configuredProviders.includes("github") && (
|
}
|
||||||
<Grid.Col span="content">
|
variant="default"
|
||||||
<Button
|
onClick={() => loginOAuthMutation.mutate("google")}
|
||||||
radius="xl"
|
loading={loginOAuthMutation.isLoading}
|
||||||
leftSection={<GithubIcon style={{ width: 14, height: 14 }} />}
|
>
|
||||||
variant="default"
|
Google
|
||||||
onClick={() => loginOAuthMutation.mutate("github")}
|
</Button>
|
||||||
loading={loginOAuthMutation.isLoading}
|
</Grid.Col>
|
||||||
>
|
)}
|
||||||
Github
|
{configuredProviders.includes("github") && (
|
||||||
</Button>
|
<Grid.Col span="content">
|
||||||
</Grid.Col>
|
<Button
|
||||||
)}
|
radius="xl"
|
||||||
{configuredProviders.includes("generic") && (
|
leftSection={
|
||||||
<Grid.Col span="content">
|
<GithubIcon style={{ width: 14, height: 14 }} />
|
||||||
<Button
|
}
|
||||||
radius="xl"
|
variant="default"
|
||||||
leftSection={<OAuthIcon style={{ width: 14, height: 14 }} />}
|
onClick={() => loginOAuthMutation.mutate("github")}
|
||||||
variant="default"
|
loading={loginOAuthMutation.isLoading}
|
||||||
onClick={() => loginOAuthMutation.mutate("generic")}
|
>
|
||||||
loading={loginOAuthMutation.isLoading}
|
Github
|
||||||
>
|
</Button>
|
||||||
Generic
|
</Grid.Col>
|
||||||
</Button>
|
)}
|
||||||
</Grid.Col>
|
{configuredProviders.includes("generic") && (
|
||||||
)}
|
<Grid.Col span="content">
|
||||||
</Grid>
|
<Button
|
||||||
<Divider
|
radius="xl"
|
||||||
label="Or continue with email"
|
leftSection={
|
||||||
labelPosition="center"
|
<OAuthIcon style={{ width: 14, height: 14 }} />
|
||||||
my="lg"
|
}
|
||||||
/>
|
variant="default"
|
||||||
|
onClick={() => loginOAuthMutation.mutate("generic")}
|
||||||
|
loading={loginOAuthMutation.isLoading}
|
||||||
|
>
|
||||||
|
Generic
|
||||||
|
</Button>
|
||||||
|
</Grid.Col>
|
||||||
|
)}
|
||||||
|
</Grid>
|
||||||
|
<Divider
|
||||||
|
label="Or continue with email"
|
||||||
|
labelPosition="center"
|
||||||
|
my="lg"
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Email"
|
label="Email"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const userContextSchema = z.object({
|
|||||||
oauth: z.boolean(),
|
oauth: z.boolean(),
|
||||||
provider: z.string(),
|
provider: z.string(),
|
||||||
configuredProviders: z.array(z.string()),
|
configuredProviders: z.array(z.string()),
|
||||||
|
disableContinue: z.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type UserContextSchemaType = z.infer<typeof userContextSchema>;
|
export type UserContextSchemaType = z.infer<typeof userContextSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user