Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparrow-auth",
"version": "2.31.0",
"version": "2.32.0",
"scripts": {
"dev": "vite dev",
"build": "vite build",
Expand Down
6 changes: 3 additions & 3 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@

<!-- Support page that opens the user's default email client with a pre-filled support email -->
{#if constants.APP_EDITION === AppEdition.MANAGED}
<Route path="/support">
<ExternalNavigation to={`mailto:${constants.SPARROW_SUPPORT_EMAIL}`}/>
</Route>
<Route path="/support">
<ExternalNavigation to={`mailto:${constants.SPARROW_SUPPORT_EMAIL}`} />
</Route>
{/if}

<!-- Wildcard route that redirects any unmatched paths to the entry point page -->
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/button/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
}

.custom-btn-primary {
height: 44px;
height: 36px;
font-weight: 400;
background-color: white;
color: black;
Expand Down
92 changes: 62 additions & 30 deletions src/lib/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,72 @@ const verifyMagicCode = async (verifyInfo: MagicCodeVerifyBody) => {
return response;
};

const updateOccaisonalUpdatesStatus = async (occaisonalUpdates: OccaisonalUpdatesBody) => {
const response = await makeRequest('POST', `${apiUrl}/aoi/user/update-occasional-updates-status`, {
body: occaisonalUpdates
})
return response;
}

const acceptTeamInvite = async (teamId: string, inviteId: string) => {
const response = await makeRequest('POST', `${apiUrl}/api/team/${teamId}/invite/user/accept/${inviteId}`, {
body: {}
})
return response;
}

const resendInviteTeam = async (teamId:string, inviteId:string)=>{
const response = await makeRequest('POST',`${apiUrl}/api/team/${teamId}/resend-invite/${inviteId}`,{})
return response;
}


export {
registerUser,
loginUser,
forgotPassword,
loginWithGoogle,
verifyEmail,
resetPassword,
getUser,
sendUserEmailVerification,
const updateOccaisonalUpdatesStatus = async (occaisonalUpdates: OccaisonalUpdatesBody) => {
const response = await makeRequest(
'POST',
`${apiUrl}/aoi/user/update-occasional-updates-status`,
{
body: occaisonalUpdates
}
);
return response;
};

const acceptTeamInvite = async (teamId: string, inviteId: string) => {
const response = await makeRequest(
'POST',
`${apiUrl}/api/team/${teamId}/invite/user/accept/${inviteId}`,
{
body: {}
}
);
return response;
};

const resendInviteTeam = async (teamId: string, inviteId: string) => {
const response = await makeRequest(
'POST',
`${apiUrl}/api/team/${teamId}/resend-invite/${inviteId}`,
{}
);
return response;
};

const getConfig = async (hubUrl: string) => {
const response = await makeRequest('GET', `${hubUrl}/api/team/config`);
return response;
};

const getSelfHostUser = async (baseUrl: string, email: string) => {
const response = await makeRequest('GET', `${baseUrl}/api/user/email/${email}`);

return response;
};

const selfHostLoginUser = async (baseUrl: string, userInfo: loginUserPostBody) => {
const response = await makeRequest('POST', `${baseUrl}/api/auth/login`, {
body: userInfo
});
return response;
};

export {
registerUser,
loginUser,
forgotPassword,
loginWithGoogle,
verifyEmail,
resetPassword,
getUser,
sendUserEmailVerification,
verifyUserEmail,
sendMagicCodeEmail,
verifyMagicCode,
updateOccaisonalUpdatesStatus,
acceptTeamInvite,
resendInviteTeam,
registerVerifiedUser
registerVerifiedUser,
getConfig,
getSelfHostUser,
selfHostLoginUser
};
20 changes: 16 additions & 4 deletions src/pages/Auth/entry-point/EntryPoint.ViewModel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { getUser, loginUser } from '$lib/services/auth.service';
import { getConfig, getUser, loginUser } from '$lib/services/auth.service';
import type { loginUserPostBody } from '$lib/utils/dto';
import { checkValidation, entrySchema } from '$lib/utils/validation';
import { navigate } from 'svelte-navigator';

//---------------- Handle Login ------------------//
export const handleEntry = async (entryCredentials) => {
return await getUser(entryCredentials.email);
return await getUser(entryCredentials.email);
};

//------------------------- Handle Login Validation -----------------//
export const handleEntryValidation = async (entryCredentials) => {
const { errorObject : response } = await checkValidation(entrySchema, entryCredentials);
return response;
const { errorObject: response } = await checkValidation(entrySchema, entryCredentials);
return response;
};

// Get Config deatils of backend
export const handleGetConfig = async (hubUrl: string) => {
hubUrl = hubUrl.trim();

//if hubUrl end with / then remove it
if (hubUrl.endsWith('/')) {
hubUrl = hubUrl.slice(0, -1);
}
const response = await getConfig(hubUrl);
return response;
};
98 changes: 96 additions & 2 deletions src/pages/Auth/entry-point/EntryPoint.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { handleEntryValidation, handleEntry } from './EntryPoint.ViewModel';
import { handleEntryValidation, handleEntry, handleGetConfig } from './EntryPoint.ViewModel';
import { sendMagicCodeEmail } from '$lib/services/auth.service';
import sparrowicon from '$lib/assets/logoSparrowSquare.svg';
import { navigate } from 'svelte-navigator';
Expand Down Expand Up @@ -40,6 +40,9 @@
let entryLoader = false;
let isSubmitting = false; // Add this new state variable
let showContinueButton = false;
let hubUrlError: string = '';
let hubUrlTouched: boolean = false;
let hubUrl: string = '';
onMount(() => {
// Check the query parameters in the URL
const urlParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -284,6 +287,97 @@
<div class="d-flex justify-content-center mt-4">
<CloudCube />
</div>
<!-- <form
class="login-form w-100 text-whiteColor ps-1 pe-1 mb-2 mt-4"
novalidate
on:submit|preventDefault={async () => {
isSubmitting = true;
hubUrlTouched = true;
hubUrlError = hubUrl.trim() === '' ? 'Self Host URL is required.' : '';
if (hubUrlError === '') {
entryLoader = true;
const response = await handleGetConfig(hubUrl);
if (response?.isSuccessful && response?.data?.identityUrl) {
// if (
// response?.data?.registeredWith === 'email' ||
// response?.data?.registeredWith === 'google'
// ) {
// Send magic code before redirecting
// sessionStorage.setItem(`selfhost-backendurl`, response?.data?.appUrl);
// sessionStorage.setItem(`selfhost-adminurl`, response?.data?.identityUrl);
// navigate(response?.data?.identityUrl);
let redirectSource = localStorage.getItem('source');
if(redirectSource === "desktop"){
window.location.href = response?.data?.identityUrl + `/init?source=desktop`;
}
else if(redirectSource === "admin"){
window.location.href = response?.data?.identityUrl + `/init?source=admin`;
}
else{
window.location.href = response?.data?.identityUrl + `/init?source=web`;
}
// await handleMagicCodeAndRedirect(entryCredentials?.email);
// } else {
// // New user - redirect to registration
// navigate(`/register/${entryCredentials?.email}`);
// }
}
else if(response?.message.startsWith('Cannot GET') || response?.message === "Internal server error"){
notifications.error('Self Host URL entered is invalid.');
}
else {
notifications.error(response?.message || 'Self Host URL entered is invalid.');
}
entryLoader = false;
}
isSubmitting = false;
}}
>
<div class="mb-3 mt-4">
<label for="exampleInputHubUrl1" class="form-label text-Gray sparrow-fs-14 d-flex"
>Self Host URL
<p class="ms-1 mb-0 sparrow-fw-600 text-dangerColor">*</p></label
>

<div class="d-flex position-relative mt-1">
<input
type="huburl"
class="form-control sparrow-fs-16 border:{hubUrlError && hubUrlTouched
? '3px'
: '1px'} solid {hubUrlError && hubUrlTouched ? 'border-error' : 'border-default'}"
id="exampleInputHubUrl1"
aria-describedby="emailHelp"
placeholder="Enter Self Host URL"
autocorrect="off"
autocapitalize="none"
autocomplete="off"
bind:value={hubUrl}
on:blur={async () => {
hubUrlTouched = true;
hubUrlError = hubUrl.trim() === '' ? 'Self Host URL is required.' : '';
}}
on:input={async () => {
hubUrlError = hubUrl.trim() === '' ? 'Self Host URL is required.' : '';
}}
/>

</div>

{#if hubUrlError && hubUrlTouched}
<small class="form-text text-dangerColor"> {hubUrlError}</small>
{/if}
</div>
<div class="mb-3">
<Button
disable={entryLoader || isSubmitting}
loader={entryLoader || isSubmitting}
title={'Continue'}
buttonClassProp={'w-100 align-items-center d-flex justify-content-center sparrow-fs-16'}
type={'primary'}
/>
</div>
</form> -->
<!-- </div> -->
<div class="self-hosting-container">
<p class="d-flex justify-content-center text-center" style="margin: 0px; color:#ffffff;">
Self Hosting is Coming Soon!
Expand All @@ -292,7 +386,7 @@
class="d-flex justify-content-center text-center"
style="margin: 0px; color:#9B9DA1; font-size:12px;"
>
Gain full control of your deployment with our upcoming self-hosting feature. Stay tuned!
Gain full control of your deployment with our self-hosting feature.
</p>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Auth/login-page/LoginPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import Button from '$lib/components/button/Button.svelte';
import BgContainer from '$lib/components/bgContainer/BgContainer.svelte';
import AiSparkle from '$lib/assets/AiSparkle.svelte';
import { AppEdition } from '$lib/utils/enums/enums';

export let id;

Expand Down Expand Up @@ -111,7 +112,7 @@
isLogin = true;
const accessToken = response?.accessToken?.token;
const refreshToken = response?.refreshToken?.token;
const sparrowRedirect = `sparrow://?accessToken=${accessToken}&refreshToken=${refreshToken}&response=${JSON.stringify(response)}&event=login&method=email`;
const sparrowRedirect = `sparrow://?selfhostBackendUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.API_URL : ""}&selfhostAdminUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.SPARROW_ADMIN_URL : ""}&selfhostWebUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.SPARROW_WEB_URL : ""}&accessToken=${accessToken}&refreshToken=${refreshToken}&response=${JSON.stringify(response)}&event=login&method=email`;
const sparrowWebRedirect =
constants.SPARROW_WEB_URL +
`?accessToken=${accessToken}&refreshToken=${refreshToken}&response=${JSON.stringify(response)}&event=login&method=email`;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Auth/oauth-redirect/OauthRedirect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import constants from '$lib/utils/constants';
import RegisterRedirectComponent from '../redirect/RegisterRedirectComponent.svelte';
import { notifications } from '$lib/components/toast-notification/ToastNotification';
import { AppEdition } from '$lib/utils/enums/enums';

let redirctSource = localStorage.getItem('source');

Expand All @@ -21,7 +22,7 @@
accessToken = urlParams.get('accessToken') as string;
refreshToken = urlParams.get('refreshToken') as string;
source = urlParams.get('source') as string;
sparrowRedirect = `sparrow://?accessToken=${accessToken}&refreshToken=${refreshToken}&event=${source}&method=google`;
sparrowRedirect = `sparrow://?selfhostBackendUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.API_URL : ""}&selfhostAdminUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.SPARROW_ADMIN_URL : ""}&selfhostWebUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.SPARROW_WEB_URL : ""}&accessToken=${accessToken}&refreshToken=${refreshToken}&event=${source}&method=google`;
sparrowWebRedirect =
constants.SPARROW_WEB_URL +
`?accessToken=${accessToken}&refreshToken=${refreshToken}&event=${source}&method=google`;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Auth/plans/Plans.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import constants from '$lib/utils/constants';
import { notifications } from '$lib/components/toast-notification/ToastNotification';
import Redirect from '../redirect/Redirect.svelte';
import { AppEdition } from '$lib/utils/enums/enums';

const location = useLocation();
let redirctSource = localStorage.getItem('source');
Expand Down Expand Up @@ -153,7 +154,7 @@
return;
} else if (plan.title === 'Community') {
isRegistered = true;
const sparrowRedirect = `sparrow://?accessToken=${accessToken}&refreshToken=${refreshToken}&response=${response}&event=register&method=email`;
const sparrowRedirect = `sparrow://?selfhostBackendUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.API_URL : ""}&selfhostAdminUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.SPARROW_ADMIN_URL : ""}&selfhostWebUrl=${constants.APP_EDITION === AppEdition.SELFHOSTED ? constants.SPARROW_WEB_URL : ""}&accessToken=${accessToken}&refreshToken=${refreshToken}&response=${response}&event=register&method=email`;
const sparrowWebRedirect =
constants.SPARROW_WEB_URL +
`?accessToken=${accessToken}&refreshToken=${refreshToken}&response=${response}&event=register&method=email`;
Expand Down
Loading