Support redirecting to families portal
This commit is contained in:
parent
312926cd1d
commit
05e57be5df
|
@ -22,6 +22,7 @@ import MessageDialog, {
|
|||
MessageAttributes,
|
||||
SetDialogMessage,
|
||||
} from 'components/MessageDialog';
|
||||
import { getFamilyPortalRedirectURL } from 'services/userService';
|
||||
|
||||
const GlobalStyles = createGlobalStyle`
|
||||
/* ubuntu-regular - latin */
|
||||
|
@ -558,8 +559,9 @@ export interface FlashMessage {
|
|||
export const AppContext = createContext<AppContextType>(null);
|
||||
|
||||
const redirectMap = {
|
||||
roadmap: (token: string) =>
|
||||
roadmap: async (token: string) =>
|
||||
`${getEndpoint()}/users/roadmap?token=${encodeURIComponent(token)}`,
|
||||
families: async () => getFamilyPortalRedirectURL(),
|
||||
};
|
||||
|
||||
export default function App({ Component, err }) {
|
||||
|
@ -630,12 +632,18 @@ export default function App({ Component, err }) {
|
|||
'font-size: 20px;'
|
||||
);
|
||||
}
|
||||
|
||||
const redirectTo = async (redirect, token) => {
|
||||
const url = await redirectMap[redirect](token);
|
||||
window.location.href = url;
|
||||
};
|
||||
|
||||
const query = new URLSearchParams(window.location.search);
|
||||
const redirect = query.get('redirect');
|
||||
if (redirect && redirectMap[redirect]) {
|
||||
const user = getData(LS_KEYS.USER);
|
||||
if (user?.token) {
|
||||
window.location.href = redirectMap[redirect](user.token);
|
||||
redirectTo(redirect, user.token);
|
||||
} else {
|
||||
setRedirectName(redirect);
|
||||
}
|
||||
|
@ -649,9 +657,7 @@ export default function App({ Component, err }) {
|
|||
if (redirectName) {
|
||||
const user = getData(LS_KEYS.USER);
|
||||
if (user?.token) {
|
||||
window.location.href = redirectMap[redirectName](
|
||||
user.token
|
||||
);
|
||||
redirectTo(redirectName, user.token);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { PAGES } from 'constants/pages';
|
||||
import { getEndpoint } from 'utils/common/apiUtil';
|
||||
import { getEndpoint, getFamilyPortalURL } from 'utils/common/apiUtil';
|
||||
import { clearKeys } from 'utils/storage/sessionStorage';
|
||||
import router from 'next/router';
|
||||
import { clearData, getData, LS_KEYS } from 'utils/storage/localStorage';
|
||||
|
@ -53,6 +53,19 @@ export const getPaymentToken = async () => {
|
|||
return resp.data['paymentToken'];
|
||||
};
|
||||
|
||||
export const getFamiliesToken = async () => {
|
||||
const token = getToken();
|
||||
|
||||
const resp = await HTTPService.get(
|
||||
`${ENDPOINT}/users/families-token`,
|
||||
null,
|
||||
{
|
||||
'X-Auth-Token': token,
|
||||
}
|
||||
);
|
||||
return resp.data['familiesToken'];
|
||||
};
|
||||
|
||||
export const verifyOtt = (email: string, ott: string) =>
|
||||
HTTPService.post(`${ENDPOINT}/users/verify-email`, { email, ott });
|
||||
|
||||
|
@ -253,3 +266,17 @@ export const getUserDetails = async (): Promise<UserDetails> => {
|
|||
});
|
||||
return resp.data['details'];
|
||||
};
|
||||
|
||||
export const getFamilyPortalRedirectURL = async () => {
|
||||
try {
|
||||
const jwtToken = await getFamiliesToken();
|
||||
const isFamilyCreated = false;
|
||||
return `${getFamilyPortalURL()}?token=${jwtToken}&isFamilyCreated=${isFamilyCreated}&redirectURL=${
|
||||
window.location.origin
|
||||
}/gallery`;
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
logError(e, 'unable to redirect to family portal');
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -42,3 +42,12 @@ export const getPaymentsURL = () => {
|
|||
}
|
||||
return `https://payments.ente.io`;
|
||||
};
|
||||
|
||||
// getFamilyPortalURL returns the endpoint for the family dashboard which can be used to
|
||||
// create or manage family.
|
||||
export const getFamilyPortalURL = () => {
|
||||
if (process.env.NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT !== undefined) {
|
||||
return process.env.NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT;
|
||||
}
|
||||
return `https://families.ente.io`;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue