Change /api/auth/login to POST.

This commit is contained in:
Yang Luo
2021-03-15 00:49:16 +08:00
parent 2a481d6a2e
commit 4a170d1d56
5 changed files with 39 additions and 32 deletions

View File

@ -44,10 +44,11 @@ export function logout() {
}).then(res => res.json());
}
export function authLogin(applicationName, providerName, code, state, redirectUri, method) {
return fetch(`${authConfig.serverUrl}/api/auth/login?application=${applicationName}&provider=${providerName}&code=${code}&state=${state}&redirect_url=${redirectUri}&method=${method}`, {
method: 'GET',
credentials: 'include',
export function authLogin(values) {
return fetch(`${authConfig.serverUrl}/api/auth/login`, {
method: 'POST',
credentials: "include",
body: JSON.stringify(values),
}).then(res => res.json());
}

View File

@ -13,9 +13,10 @@
// limitations under the License.
import React from "react";
import {message, Spin} from "antd";
import {Spin} from "antd";
import {withRouter} from "react-router-dom";
import * as AuthBackend from "./AuthBackend";
import * as Util from "./Util";
class AuthCallback extends React.Component {
constructor(props) {
@ -35,26 +36,22 @@ class AuthCallback extends React.Component {
}
componentWillMount() {
this.authLogin();
}
showMessage(type, text) {
if (type === "success") {
message.success(text);
} else if (type === "error") {
message.error(text);
}
}
authLogin() {
let redirectUri;
redirectUri = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`;
AuthBackend.authLogin(this.state.applicationName, this.state.providerName, this.state.code, this.state.state, redirectUri, this.state.method)
const body = {
application: this.state.applicationName,
provider: this.state.providerName,
code: this.state.code,
state: this.state.state,
redirectUri: redirectUri,
method: this.state.method,
};
AuthBackend.authLogin(body)
.then((res) => {
if (res.status === "ok") {
window.location.href = '/';
} else {
this.showMessage("error", res?.msg);
Util.showMessage("error", res?.msg);
}
});
}