title: Define a constant instead of duplicating this literal 3 times sonar
body: <p>I am wondering how I would refactor the following. Basically, after I get the user information from google, it is validated since a specific domain might be allowed. If it passes that one, we validate the token against a back end api.</p>
  <p>Sonar is complaining on the use of <strong>return displayAlert('LoginFailed')</strong> three times. Given the methods have unique use, I am wondering what could be done to improve it?</p>
  <pre><code>import React, {useContext} from 'react';
  import {View, Alert} from 'react-native';
  import {LocalizationContext} from 'library/localization';
  import ServiceAuth from 'services/ServiceAuth';
  import {saveLoggedInDetails} from 'library/userInformation';
  
  const MyComponent = (props) =&gt; {
    const {translations} = useContext(LocalizationContext);
  
    const displayAlert = (msg) =&gt;{
        //translations happen here
      Alert.alert(&quot;Failed&quot;, msg)
      return false;
    }
  
  
    const validateToken = async (userGoogleInfo) =&gt; {
      const {idToken} = userGoogleInfo;
      let serviceAuth = ServiceAuth.getInstance();
      try {
        return await serviceAuth.validateT(idToken);
      } catch (error) {
        //show alert here
        return displayAlert('LoginFailed')
      }
    };
  
  
    const authorize = async (userGoogleInfo) =&gt; {
      const allowedDomains = [];
      let reply = {ok: false};
      //check if domain is allowed etc and set to true.
      if (!reply['ok']) {
        return displayAlert('InvalidDomain');
      }
  
      try {
        const userInfo = await validateToken(userGoogleInfo);
  
        if (userInfo) {
         console.log(&quot;okay&quot;)
        } else {
          return displayAlert('LoginFailed')
        }
      } catch (error) {
        return displayAlert('LoginFailed')
      }
    };
  
    return (
      &lt;&gt;
          &lt;View&gt;
            &lt;Text&gt;Hello&lt;/Text&gt;
          &lt;/View&gt;
      &lt;/&gt;
    );
  };
  export default MyComponent;
  </code></pre>