diff --git a/packages/hoppscotch-sh-admin/locales/en.json b/packages/hoppscotch-sh-admin/locales/en.json index a4d58bfd..2d88b1b6 100644 --- a/packages/hoppscotch-sh-admin/locales/en.json +++ b/packages/hoppscotch-sh-admin/locales/en.json @@ -305,6 +305,7 @@ "continue_email": "Continue with Email", "continue_github": "Continue with Github", "continue_google": "Continue with Google", + "continue_local": "Continue with username", "continue_microsoft": "Continue with Microsoft", "copied_to_clipboard": "Copied to clipboard", "create_team_failure": "Failed to create workspace!!", @@ -345,6 +346,7 @@ "login_using_email": "Please ask the user to check their email or share the link below", "login_using_link": "Please ask the user to login using the link below", "logout": "Logout", + "local_signin_failure": "Failed to login with username and password", "magic_link_sign_in": "Click on the link to sign in.", "magic_link_success": "We sent a magic link to", "microsoft_signin_failure": "Failed to login with Microsoft", @@ -352,6 +354,7 @@ "non_admin_logged_in": "Logged in as non admin user.", "non_admin_login": "You are logged in. But you're not an admin", "owner_not_present": "Atleast one owner should be present in the team!!", + "password": "Password", "privacy_policy": "Privacy Policy", "reenter_email": "Re-enter email", "remove_admin_failure": "Failed to remove admin status!!", @@ -380,12 +383,14 @@ "send_magic_link": "Send magic link", "setup_failure": "Setup has failed!!", "setup_success": "Setup completed successfully!!", + "sign_in": "Sign in", "sign_in_agreement": "By signing in, you are agreeing to our", "sign_in_options": "All sign in option", "sign_out": "Sign out", "something_went_wrong": "Something went wrong", "team_name_too_short": "Workspace name should be atleast 6 characters long!!", "user_already_invited": "Failed to send invite. User is already invited!!", + "username": "Username", "user_not_found": "User not found in the infra!!", "users_to_admin_success": "Selected users are elevated to admin status!!", "users_to_admin_failure": "Failed to elevate selected users to admin status!!" diff --git a/packages/hoppscotch-sh-admin/locales/fr.json b/packages/hoppscotch-sh-admin/locales/fr.json index 13ebdc2d..9bf82e5a 100644 --- a/packages/hoppscotch-sh-admin/locales/fr.json +++ b/packages/hoppscotch-sh-admin/locales/fr.json @@ -13,5 +13,12 @@ "username_format": "L’identifiant ne peut contenir que des lettres, chiffres, points, tirets et underscores.", "username_min_length": "L’identifiant doit contenir au moins 3 caractères." } + }, + "state": { + "continue_local": "Continuer avec un identifiant", + "local_signin_failure": "Connexion avec identifiant et mot de passe impossible", + "password": "Mot de passe", + "sign_in": "Se connecter", + "username": "Identifiant" } } diff --git a/packages/hoppscotch-sh-admin/src/components/app/Login.vue b/packages/hoppscotch-sh-admin/src/components/app/Login.vue index 1017d355..cf3109ed 100644 --- a/packages/hoppscotch-sh-admin/src/components/app/Login.vue +++ b/packages/hoppscotch-sh-admin/src/components/app/Login.vue @@ -51,6 +51,12 @@ :label="t('state.continue_email')" @click="mode = 'email'" /> +
+
+ + + + +
-
+
{ signingInWithEmail.value = false; }; +const signInWithUsernamePassword = async () => { + signingInWithLocal.value = true; + try { + await auth.signInWithUsernamePassword( + form.value.username, + form.value.password, + ); + + if (auth.getCurrentUser()?.isAdmin) { + window.location.href = import.meta.env.VITE_ADMIN_URL; + } else { + nonAdminUser.value = true; + } + } catch (e) { + console.error(e); + toast.error(t('state.local_signin_failure')); + } + signingInWithLocal.value = false; +}; + const getAllowedAuthProviders = async () => { fetching.value = true; try { diff --git a/packages/hoppscotch-sh-admin/src/helpers/auth.ts b/packages/hoppscotch-sh-admin/src/helpers/auth.ts index 098d72f1..5a7c38d7 100644 --- a/packages/hoppscotch-sh-admin/src/helpers/auth.ts +++ b/packages/hoppscotch-sh-admin/src/helpers/auth.ts @@ -222,6 +222,11 @@ export const auth = { } }, + signInWithUsernamePassword: async (username: string, password: string) => { + await authQuery.signInLocal(username, password); + await setInitialUser(); + }, + performAuthRefresh: async () => { const isRefreshSuccess = await refreshToken(); diff --git a/packages/hoppscotch-sh-admin/src/helpers/backend/rest/authQuery.ts b/packages/hoppscotch-sh-admin/src/helpers/backend/rest/authQuery.ts index 00d8af07..2b07fd87 100644 --- a/packages/hoppscotch-sh-admin/src/helpers/backend/rest/authQuery.ts +++ b/packages/hoppscotch-sh-admin/src/helpers/backend/rest/authQuery.ts @@ -34,6 +34,11 @@ export default { username, password, }), + signInLocal: (username: string, password: string) => + restApi.post('/auth/local/signin', { + username, + password, + }), getFirstTimeInfraSetupStatus: () => restApi.get('/site/setup'), updateFirstTimeInfraSetupStatus: () => restApi.put('/site/setup'), addOnBoardingConfigs: (config: Record) =>