📈 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
implemented google login button
Blue Mousedaed5a9c878a
diff --git a/.env.example b/.env.exampleindex 96b340cf9..fcada8216 100644--- a/.env.example+++ b/.env.example@@ -2,5 +2,8 @@ REACT_APP_API_URL=https://api.swetrix.com/REACT_APP_CDN_URL=https://cdn.swetrix.com/REACT_APP_BLOG_URL=https://blog.swetrix.com/REACT_APP_AIAPI_URL=https://aiapi.swetrix.com/++REACT_APP_GOOGLE_CLIENT_ID=+CHOKIDAR_USEPOLLING=trueGENERATE_SOURCEMAP=falsediff --git a/public/locales/en.json b/public/locales/en.jsonindex f667cda91..32b0e7d09 100644--- a/public/locales/en.json+++ b/public/locales/en.json@@ -293,7 +293,8 @@"signin": "Sign in","checkLeakedPassword": "Check if password is leaked","checkLeakedPasswordDesc": "When enabled we check your password with the <db>{{database}}</db> database. We don't send your password to the service. First we hash your password (using SHA1) and send only the first 5 characters of that hash to the service. The service returns all leaked passwords that start with those 5 characters. At our end we check if one of these matches with your password. We show you a warning if it has been leaked before. We never store your password in plain text.",- "addedOn": "Added on"+ "addedOn": "Added on",+ "continueWithGoogle": "Continue with Google"}},"features": {diff --git a/src/components/GoogleAuth.tsx b/src/components/GoogleAuth.tsxnew file mode 100644index 000000000..9a7a9a7e7--- /dev/null+++ b/src/components/GoogleAuth.tsx@@ -0,0 +1,92 @@+import React, { useEffect, useRef } from 'react'+import { useTranslation } from 'react-i18next'++import Button from 'ui/Button'+import GoogleGSVG from 'ui/icons/GoogleG'++const googleScriptSrc = 'https://accounts.google.com/gsi/client'+const clientId = process.env.REACT_APP_GOOGLE_CLIENT_ID++const loadScript = (src: string): Promise<any> => new Promise((resolve, reject) => {+ if (document.querySelector(`script[src='${src}']`)) {+ resolve(null)+ }++ const script = document.createElement('script')+ script.src = src+ script.onload = resolve+ script.onerror = reject+ document.body.appendChild(script)+})++const GoogleAuth = () => {+ const { t } = useTranslation()+ const actualGoogleButton = useRef(null)++ // useEffect(() => {+ // if (actualGoogleButton.current) {+ // // @ts-ignore+ // actualGoogleButton.current.click()+ // }+ // }, [actualGoogleButton.current])++ const handleCredentialResponse = (response: any) => {+ console.log(response)+ }++ const renderGoogleLoginButton = async () => {+ try {+ await loadScript(googleScriptSrc)++ // @ts-ignore+ window.google.accounts.id.initialize({+ client_id: clientId,+ callback: handleCredentialResponse,+ })++ // @ts-ignore+ window.google.accounts.id.renderButton(+ actualGoogleButton.current,+ { theme: 'outline', size: 'large' },+ )+ } catch (error) {+ // todo: display error notification+ console.error(error)+ }+ }++ const clickGoogleLoginButton = () => {+ if (actualGoogleButton.current) {+ // @ts-ignore+ actualGoogleButton.current.click()+ }+ }++ const googleLogin = async () => {+ await renderGoogleLoginButton()+ clickGoogleLoginButton()+ }++ return (+ <div>+ <Button+ className='mr-2 border-indigo-100 dark:text-gray-50 dark:border-gray-700 dark:bg-gray-700 dark:hover:bg-gray-600'+ onClick={googleLogin}+ secondary+ regular+ >+ <>+ <GoogleGSVG className='w-5 h-5 mr-2' />+ {t('auth.common.continueWithGoogle')}+ </>+ </Button>+ <div+ className='hidden'+ ref={actualGoogleButton}+ onClick={() => { }}+ />+ </div>+ )+}++export default GoogleAuthdiff --git a/src/pages/Auth/Signup/Signup.tsx b/src/pages/Auth/Signup/Signup.tsxindex cf63cd65f..d70f8ccb1 100644--- a/src/pages/Auth/Signup/Signup.tsx+++ b/src/pages/Auth/Signup/Signup.tsx@@ -7,6 +7,7 @@ import _keys from 'lodash/keys'import _isEmpty from 'lodash/isEmpty'import Title from 'components/Title'+import GoogleAuth from 'components/GoogleAuth'import { withAuthentication, auth } from 'hoc/protected'import routes from 'routes'import Input from 'ui/Input'@@ -249,6 +250,7 @@ const Signup = ({ signup }: {{t('auth.signup.button')}</Button></div>+ <GoogleAuth /></form></div></Title>diff --git a/src/ui/icons/GoogleG.tsx b/src/ui/icons/GoogleG.tsxnew file mode 100644index 000000000..dff58364a--- /dev/null+++ b/src/ui/icons/GoogleG.tsx@@ -0,0 +1,25 @@+import React from 'react'+import PropTypes from 'prop-types'++const GoogleGSVG = ({ className }: {+ className?: string,+}): JSX.Element => (+ <svg className={className} viewBox='0 0 186.69 190.5'>+ <g transform='translate(1184.583 765.171)'>+ <path clipPath='none' mask='none' d='M-1089.333-687.239v36.888h51.262c-2.251 11.863-9.006 21.908-19.137 28.662l30.913 23.986c18.011-16.625 28.402-41.044 28.402-70.052 0-6.754-.606-13.249-1.732-19.483z' fill='#4285f4' />+ <path clipPath='none' mask='none' d='M-1142.714-651.791l-6.972 5.337-24.679 19.223h0c15.673 31.086 47.796 52.561 85.03 52.561 25.717 0 47.278-8.486 63.038-23.033l-30.913-23.986c-8.486 5.715-19.31 9.179-32.125 9.179-24.765 0-45.806-16.712-53.34-39.226z' fill='#34a853' />+ <path clipPath='none' mask='none' d='M-1174.365-712.61c-6.494 12.815-10.217 27.276-10.217 42.689s3.723 29.874 10.217 42.689c0 .086 31.693-24.592 31.693-24.592-1.905-5.715-3.031-11.776-3.031-18.098s1.126-12.383 3.031-18.098z' fill='#fbbc05' />+ <path clipPath='none' mask='none' d='M-1089.333-727.244c14.028 0 26.497 4.849 36.455 14.201l27.276-27.276c-16.539-15.413-38.013-24.852-63.731-24.852-37.234 0-69.359 21.388-85.032 52.561l31.692 24.592c7.533-22.514 28.575-39.226 53.34-39.226z' fill='#ea4335' />+ </g>+ </svg>+)++GoogleGSVG.propTypes = {+ className: PropTypes.string,+}++GoogleGSVG.defaultProps = {+ className: '',+}++export default GoogleGSVG