Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

social-auth-app-django Google Login and React-Native

$
0
0

I'm using the social-auth-app-Django library on my Django Rest API (DRF) to authenticate users with social providers. I am using the expo-auth-session library (though this could be changed) in my React Native frontend to open a webbrowser instance for the client to use to log in with social providers (i.e. google). The issue is that once the login is succesful, the small window from the webbrowser instance instead of closing, redirects back to the App in the small browser window.

settings.py

TEMPLATES = [    {'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [BASE_DIR / 'templates']        ,'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages','social_django.context_processors.backends','social_django.context_processors.login_redirect',            ],        },    },]AUTHENTICATION_BACKENDS = ('social_core.backends.google.GoogleOAuth2','django.contrib.auth.backends.ModelBackend',)for key in ['GOOGLE_OAUTH2_KEY','GOOGLE_OAUTH2_SECRET', ]:    exec("SOCIAL_AUTH_{key} = os.environ.get('{key}')".format(key=key))SOCIAL_AUTH_LOGIN_REDIRECT_URL  = 'http://localhost:19006/'

urls.py

from django.contrib import adminfrom django.urls import path, includeurlpatterns = [    path('oauth/', include('social_django.urls', namespace='social')),]

index.tsx

const signInGoogle = async () => {  const redirectUri = AuthSession.makeRedirectUri({    useProxy: true,  });  const result = await WebBrowser.openAuthSessionAsync(    `http://localhost:8000/oauth/login/google-oauth2?next=${redirectUri}`,    redirectUri  );  console.log(result);};

Once the login is succesful, the small window from the webbrowser instance instead of closing, redirects back to the App/WebApp in the small browser window.


Viewing all articles
Browse latest Browse all 6290

Trending Articles