Anonymous
Redirect Uri не работает в React Native
Сообщение
Anonymous » 27 ноя 2025, 03:09
Мое мобильное приложение с использованием React Native, которое я создаю с помощью eas build -p android --profile Preview. Он создал qr-код, с помощью которого я загрузил свой apk-файл и установил его. Когда я открываю приложение, оно работает. Там отображается кнопка «Войти», которая просит выбрать почту. После выбора почты он показывает «одну минуту, пожалуйста» и перенаправляет в браузер. Почему? В чем ошибка?
Код: Выделить всё
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"
}
}
}
}
Eas.json:
Код: Выделить всё
{
"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": {}
}
}
Я добавил имя пакета в консоль Google Cloud, например com.subash0396.mynewapp. Я также добавил отпечаток сертификата SHA-1.
Подробнее здесь:
https://stackoverflow.com/questions/798 ... act-native
1764202192
Anonymous
Мое мобильное приложение с использованием React Native, которое я создаю с помощью eas build -p android --profile Preview. Он создал qr-код, с помощью которого я загрузил свой apk-файл и установил его. Когда я открываю приложение, оно работает. Там отображается кнопка «Войти», которая просит выбрать почту. После выбора почты он показывает «одну минуту, пожалуйста» и перенаправляет в браузер. Почему? В чем ошибка? [code]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 })} /> ); } [/code] Код работает, но почему он не перенаправляет меня должным образом в мое приложение? app.json: [code]{ "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" } } } } [/code] Eas.json: [code]{ "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": {} } } [/code] Я добавил имя пакета в консоль Google Cloud, например com.subash0396.mynewapp. Я также добавил отпечаток сертификата SHA-1. Подробнее здесь: [url]https://stackoverflow.com/questions/79824156/redirect-uri-is-not-working-in-react-native[/url]