Reformating route and renaming firm and correcting login redirections
This commit is contained in:
@@ -7,9 +7,12 @@ const LOCAL_STORAGE_USER_KEY = "rpk-gui-current-user";
|
||||
const GOOGLE_SCOPES = { "scopes": "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email" };
|
||||
const DISCORD_SCOPES = { "scopes": "identify email" }
|
||||
|
||||
const DEFAULT_LOGIN_REDIRECT = "/hub"
|
||||
|
||||
export const authProvider: AuthProvider = {
|
||||
login: async ({ providerName, email, password }) => {
|
||||
const to_param = findGetParameter("to");
|
||||
const redirect = to_param === null ? DEFAULT_LOGIN_REDIRECT : to_param
|
||||
if (providerName) {
|
||||
let scope = {};
|
||||
if (providerName === "google") {
|
||||
@@ -22,11 +25,14 @@ export const authProvider: AuthProvider = {
|
||||
const response = await fetch(url, { method: "GET", },);
|
||||
const body = await response.json();
|
||||
|
||||
if (to_param) {
|
||||
localStorage.setItem("redirect_after_login", to_param);
|
||||
}
|
||||
|
||||
localStorage.setItem("redirect_after_login", redirect);
|
||||
|
||||
window.location.href = body.authorization_url;
|
||||
return { success: true };
|
||||
return {
|
||||
success: true,
|
||||
redirectTo: ""
|
||||
};
|
||||
} else if (email !== undefined && password !== undefined) {
|
||||
const params = new URLSearchParams({"grant_type": "password", "username": email, "password": password});
|
||||
const response = await fetch(
|
||||
@@ -42,7 +48,10 @@ export const authProvider: AuthProvider = {
|
||||
const user = await response.json();
|
||||
store_user(user);
|
||||
|
||||
return { success: true };
|
||||
return {
|
||||
success: true,
|
||||
redirectTo: redirect,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +69,7 @@ export const authProvider: AuthProvider = {
|
||||
if (get_user() == null) {
|
||||
return {
|
||||
authenticated: false,
|
||||
redirectTo: "/login",
|
||||
redirectTo: "/auth/login",
|
||||
logout: true
|
||||
}
|
||||
}
|
||||
@@ -142,7 +151,7 @@ export const authProvider: AuthProvider = {
|
||||
if (error?.status === 401) {
|
||||
forget_user();
|
||||
return {
|
||||
redirectTo: "/login",
|
||||
redirectTo: "/auth/login",
|
||||
logout: true,
|
||||
error: { message: "Authentication required" },
|
||||
} as OnErrorResponse;
|
||||
|
||||
Reference in New Issue
Block a user