Код: Выделить всё
import * as AuthSession from "expo-auth-session";
import * as Google from "expo-auth-session/providers/google";
import * as WebBrowser from "expo-web-browser";
import React from "react";
import { Button, Text, View } from "react-native";
WebBrowser.maybeCompleteAuthSession();
export default function GoogleSignInScreen() {
const [log, setLog] = React.useState('');
const [request, response, promptAsync] = Google.useAuthRequest({
androidClientId: "xxxxxxxxxxxxxxxxxxxxxxxxx",
clientId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
responseType: "code",
});
// console.log(AuthSession.makeRedirectUri());
const redirectUri = AuthSession.makeRedirectUri({
native: `com.subash0396.mynewapp:/oauthredirect`
});
React.useEffect(() => {
if (response) {
setLog(JSON.stringify(response));
}
console.log("Google Response:", response);
if (response?.type === "success") {
const code = response.params.code;
console.log("success:", code);
fetch("http://192.168.29.33:8000/api/google-signin/signin/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code }),
})
.then(res => res.json())
.then(data => console.log("Django Response:", data))
.catch(err => console.log("Backend Error:", err));
}
}, [response]);
return (
Google Sign-In
{log}
promptAsync({ showInRecents: true })}
/>
);
}
app.json:
Код: Выделить всё
{
"expo": {
"name": "MyNewApp",
"slug": "mynewapp",
"scheme": "mynewapp",
"platforms": [
"android",
"ios"
],
"android": {
"package": "com.subash0396.mynewapp"
},
"ios": {
"bundleIdentifier": "com.subash0396.mynewapp"
},
"owner": "subash0396",
"extra": {
"eas": {
"projectId": "0f8a2386-e6c5-45b0-ae27-f16f5899a581"
}
}
}
}
Код: Выделить всё
{
"cli": {
"version": ">= 16.27.0",
"appVersionSource": "remote"
},
"build": {
"development": {
"android": {
"buildType": "apk"
},
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"android": {
"buildType": "apk"
},
"distribution": "internal"
},
"production": {
"android": {
"buildType": "app-bundle"
},
"autoIncrement": true
}
},
"submit": {
"production": {}
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... act-native