Search code examples
pythondjangogoogle-oauthdjango-allauth

Django Allauth's Google Login Redirect and Page Design


Currently, on the login page, I have a button:

<div class="d-grid gap-2">
    <a href="{% provider_login_url 'google' %}" class="btn btn-danger">
        <i class="fab fa-google"></i> Sign in with Google
    </a>
</div>

This redirects to accounts/google/login/, and that page allows for redirection to Google authentication.

I have two problems:

  1. I don't know if these two steps are necessary and I don't see the value of having the extra step accounts/google/login/.
  2. I don't know how to replace the standard layout of the accounts/google/login/ page (in case it is really needed).

Solution

  • To answer your first question, I really don't think an extra step is necessary. On the other hand, though, it depends on the application, and there's really nothing wrong with leaving your current option.

    Regarding doing it all on one page, it's possible and would require minimal code, something like this should work if everything is set up correctly:

    {#Other code#}  
    <form method="POST" action="{% url 'google_login' %}">  
      {% csrf_token %}  
      <button type="submit">GOOGLE</button>  
    </form>  
    {#Other code#}  
    

    We can immediately open the Google login window using form action=“{% url ‘google_login’ %}”. If you have SOCIALACCOUNT_LOGIN_ON_GET=True in your settings, then it will be: form method=“GET”....

    p.s. If this option doesn't work for you, let me know, I can suggest something else.