📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
using generalised SSO endpoints, added github link / unlink
Blue Mouse6d4916a55495
diff --git a/src/api/index.ts b/src/api/index.tsindex 11f5a5479..0068f7634 100644--- a/src/api/index.ts+++ b/src/api/index.ts@@ -822,9 +822,9 @@ export const generateSSOAuthURL = (provider: string) =>: error.response.data.message})-export const getJWTByGoogleHash = (hash: string) =>+export const getJWTBySSOHash = (hash: string, provider: string) =>api- .post('v1/auth/google/hash', { hash })+ .post('v1/auth/sso/hash', { hash, provider }).then((response): unknown => response.data).catch((error) => {debug('%s', error)@@ -833,9 +833,9 @@ export const getJWTByGoogleHash = (hash: string) =>: error.response.data.message})-export const linkByGoogleHash = (hash: string) =>+export const linkBySSOHash = (hash: string, provider: string) =>api- .post('v1/auth/google/link_by_hash', { hash })+ .post('v1/auth/sso/link_by_hash', { hash, provider }).then((response): unknown => response.data).catch((error) => {debug('%s', error)@@ -844,9 +844,9 @@ export const linkByGoogleHash = (hash: string) =>: error.response.data.message})-export const unlinkGoogle = () =>+export const unlinkSSO = (provider: string) =>api- .delete('v1/auth/google/unlink')+ .delete('v1/auth/sso/unlink', { data: { provider } }).then((response): unknown => response.data).catch((error) => {debug('%s', error)diff --git a/src/pages/UserSettings/UserSettings.container.tsx b/src/pages/UserSettings/UserSettings.container.tsxindex 280d1fdc9..8233beaa6 100644--- a/src/pages/UserSettings/UserSettings.container.tsx+++ b/src/pages/UserSettings/UserSettings.container.tsx@@ -16,7 +16,7 @@ const mapStateToProps = (state: StateType) => {user: state.auth.user,dontRemember: state.auth.dontRemember,isPaidTierUsed: state.auth.isPaidTierUsed,- // themeType: state.ui.theme.type,+ theme: state.ui.theme.theme,}}diff --git a/src/pages/UserSettings/UserSettings.tsx b/src/pages/UserSettings/UserSettings.tsxindex 1b7b5f4f4..3207038e6 100644--- a/src/pages/UserSettings/UserSettings.tsx+++ b/src/pages/UserSettings/UserSettings.tsx@@ -70,6 +70,7 @@ interface IProps {isPaidTierUsed: boolean,linkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,unlinkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,+ theme: string,}interface IForm extends Partial<IUser> {@@ -83,7 +84,7 @@ const UserSettings = ({setProjectsShareData, userSharedUpdate, sharedProjectError, updateUserData,genericError, onGDPRExportFailed, updateProfileFailed, updateUserProfileAsync,accountUpdated, setAPIKey, user, dontRemember, isPaidTierUsed, // setThemeType, themeType,- linkSSO, unlinkSSO,+ linkSSO, unlinkSSO, theme,}: IProps): JSX.Element => {const history = useHistory()const { t }: {@@ -553,6 +554,7 @@ const UserSettings = ({genericError={genericError}linkSSO={linkSSO}unlinkSSO={unlinkSSO}+ theme={theme}/>{/* Shared projects setting */}@@ -717,6 +719,7 @@ UserSettings.propTypes = {isPaidTierUsed: PropTypes.bool.isRequired,linkSSO: PropTypes.func.isRequired,unlinkSSO: PropTypes.func.isRequired,+ theme: PropTypes.string.isRequired,}export default memo(withAuthentication(UserSettings, auth.authenticated))diff --git a/src/pages/UserSettings/components/Socialisations.tsx b/src/pages/UserSettings/components/Socialisations.tsxindex 99f17ff4a..c11489c0d 100644--- a/src/pages/UserSettings/components/Socialisations.tsx+++ b/src/pages/UserSettings/components/Socialisations.tsx@@ -7,14 +7,28 @@ import {import Button from 'ui/Button'import Google from 'ui/icons/GoogleG'+import GithubDark from 'ui/icons/GithubDark'+import GithubLight from 'ui/icons/GithubLight'import { IUser } from 'redux/models/IUser'import { SSO_PROVIDERS } from 'redux/constants'-const AVAILABLE_SOCIALISATIONS = [+const AVAILABLE_SSO_PROVIDERS = [{name: 'Google',key: SSO_PROVIDERS.GOOGLE,Icon: Google,+ icons: {+ Dark: Google,+ Light: Google,+ },+ },+ {+ name: 'Github',+ key: SSO_PROVIDERS.GITHUB,+ icons: {+ Dark: GithubDark,+ Light: GithubLight,+ },},]@@ -38,30 +52,31 @@ interface ISocialisations {linkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,unlinkSSO: (t: (key: string) => string, callback: (e: any) => void, provider: string) => void,genericError: (message: string) => void,+ theme: string}const Socialisations = ({- user, linkSSO, unlinkSSO, genericError,+ user, linkSSO, unlinkSSO, genericError, theme,}: ISocialisations) => {const { t }: {t: (key: string) => string,} = useTranslation('common')const [isLoading, setIsLoading] = useState(false)- const _linkSSO = (key: string) => {+ const _linkSSO = (provider: string) => {setIsLoading(true)linkSSO(t, () => {setIsLoading(false)- }, key)+ }, provider)}- const _unlinkSSO = (key: string) => {+ const _unlinkSSO = (provider: string) => {setIsLoading(true)unlinkSSO(t, () => {setIsLoading(false)- }, key)+ }, provider)}return (@@ -72,10 +87,11 @@ const Socialisations = ({<div className='overflow-hidden bg-white dark:bg-gray-700 mt-2 shadow sm:rounded-md'><ul className='divide-y divide-gray-200'>{- _map(AVAILABLE_SOCIALISATIONS, ({- name, key, Icon,+ _map(AVAILABLE_SSO_PROVIDERS, ({+ name, key, icons,}) => {const [connected, unlinkable] = getStatusByUser(user, key)+ const { Light, Dark } = iconsconst status = connected ? 'connected' : 'notConnected'@@ -84,7 +100,11 @@ const Socialisations = ({<div className='sm:flex items-center px-1 py-4 sm:px-6'><div className='flex min-w-0 flex-1 items-center'><div className='flex-shrink-0 hidden sm:block'>- <Icon className='max-h-12 max-w-12 h-12 w-12 rounded-full' />+ {theme === 'dark' ? (+ <Light className='max-h-12 max-w-12 h-12 w-12 rounded-full' />+ ) : (+ <Dark className='max-h-12 max-w-12 h-12 w-12 rounded-full' />+ )}</div><div className='min-w-0 flex-1 px-2 sm:px-4 md:grid md:grid-cols-2 md:gap-4'><div>diff --git a/src/redux/sagas/auth/workers/sso_auth.ts b/src/redux/sagas/auth/workers/sso_auth.tsindex 9ab91faee..36cd8fe5a 100644--- a/src/redux/sagas/auth/workers/sso_auth.ts+++ b/src/redux/sagas/auth/workers/sso_auth.ts@@ -4,7 +4,7 @@ import { authActions } from 'redux/reducers/auth'import { errorsActions } from 'redux/reducers/errors'import { setAccessToken } from 'utils/accessToken'import {- getJWTByGoogleHash, generateSSOAuthURL,+ getJWTBySSOHash, generateSSOAuthURL,} from 'api'import { setRefreshToken } from 'utils/refreshToken'import { openBrowserWindow } from 'utils/generic'@@ -24,7 +24,11 @@ interface ISSOAuth {}}-export default function* ssoAuth({ payload: { callback, dontRemember, t, provider } }: ISSOAuth) {+export default function* ssoAuth({+ payload: {+ callback, dontRemember, t, provider,+ },+}: ISSOAuth) {const authWindow = openBrowserWindow('', AUTH_WINDOW_WIDTH, AUTH_WINDOW_HEIGHT)if (!authWindow) {@@ -52,7 +56,7 @@ export default function* ssoAuth({ payload: { callback, dontRemember, t, providetry {const {accessToken, refreshToken, user,- } = yield call(getJWTByGoogleHash, uuid)+ } = yield call(getJWTBySSOHash, uuid, provider)authWindow.close()yield put(authActions.setDontRemember(dontRemember))diff --git a/src/redux/sagas/auth/workers/sso_link.ts b/src/redux/sagas/auth/workers/sso_link.tsindex 757e07aa9..e7def5607 100644--- a/src/redux/sagas/auth/workers/sso_link.ts+++ b/src/redux/sagas/auth/workers/sso_link.ts@@ -4,7 +4,7 @@ import { authActions } from 'redux/reducers/auth'import { errorsActions } from 'redux/reducers/errors'import { alertsActions } from 'redux/reducers/alerts'import {- linkByGoogleHash, generateSSOAuthURL, authMe,+ linkBySSOHash, generateSSOAuthURL, authMe,} from 'api'import { openBrowserWindow } from 'utils/generic'@@ -17,10 +17,11 @@ export interface ISSOLink {payload: {callback: (isSuccess: boolean) => voidt: (key: string) => string+ provider: string}}-export default function* ssoLink({ payload: { callback, t } }: ISSOLink) {+export default function* ssoLink({ payload: { callback, t, provider } }: ISSOLink) {const authWindow = openBrowserWindow('', AUTH_WINDOW_WIDTH, AUTH_WINDOW_HEIGHT)if (!authWindow) {@@ -34,7 +35,7 @@ export default function* ssoLink({ payload: { callback, t } }: ISSOLink) {try {const {uuid, auth_url: authUrl, expires_in: expiresIn,- } = yield call(generateSSOAuthURL)+ } = yield call(generateSSOAuthURL, provider)// Set the URL of the authentification browser windowauthWindow.location = authUrl@@ -46,7 +47,7 @@ export default function* ssoLink({ payload: { callback, t } }: ISSOLink) {yield delay(HASH_CHECK_FREQUENCY)try {- yield call(linkByGoogleHash, uuid)+ yield call(linkBySSOHash, uuid, provider)authWindow.close()// @ts-ignorediff --git a/src/redux/sagas/auth/workers/sso_unlink.ts b/src/redux/sagas/auth/workers/sso_unlink.tsindex 46fc9929a..8e4c8f030 100644--- a/src/redux/sagas/auth/workers/sso_unlink.ts+++ b/src/redux/sagas/auth/workers/sso_unlink.ts@@ -6,7 +6,7 @@ import { authActions } from 'redux/reducers/auth'import { errorsActions } from 'redux/reducers/errors'import { alertsActions } from 'redux/reducers/alerts'import {- unlinkGoogle, authMe,+ unlinkSSO, authMe,} from 'api'import { SSO_PROVIDERS } from 'redux/constants'@@ -25,9 +25,7 @@ export default function* ssoUnlink({ payload: { provider, t, callback } }: ISSOU}try {- if (provider === SSO_PROVIDERS.GOOGLE) {- yield call(unlinkGoogle)- }+ yield call(unlinkSSO, provider)// @ts-ignoreconst user = yield call(authMe)diff --git a/src/ui/icons/GithubDark.tsx b/src/ui/icons/GithubDark.tsxindex 4a56b621f..0c2f52d49 100644--- a/src/ui/icons/GithubDark.tsx+++ b/src/ui/icons/GithubDark.tsx@@ -5,7 +5,7 @@ const GithubDarkSVG = ({ className }: {className?: string,}): JSX.Element => (<svg className={className} viewBox='0 0 100 100'>- <path fillRule='evenodd' clipRule='evenodd' d='M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z' fill='#24292f'/>+ <path fillRule='evenodd' clipRule='evenodd' d='M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z' fill='#24292f' /></svg>)diff --git a/src/ui/icons/GithubLight.tsx b/src/ui/icons/GithubLight.tsxindex 449601215..1d319cf49 100644--- a/src/ui/icons/GithubLight.tsx+++ b/src/ui/icons/GithubLight.tsx@@ -5,7 +5,7 @@ const GithubLightSVG = ({ className }: {className?: string,}): JSX.Element => (<svg className={className} viewBox='0 0 100 100'>- <path fillRule='evenodd' clipRule='evenodd' d='M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z' fill='#fff'/>+ <path fillRule='evenodd' clipRule='evenodd' d='M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z' fill='#fff' /></svg>)