[#34] added ky and condition to reconnect user on refresh
This commit is contained in:
@@ -9,8 +9,6 @@ import { getCalendarsListAsync } from "../Calendars/CalendarSlice";
|
||||
export function CallbackResume() {
|
||||
const dispatch = useAppDispatch();
|
||||
const hasRun = useRef(false);
|
||||
const calendars = useAppSelector((state) => state.calendars);
|
||||
const userId = useAppSelector((state) => state.user.userData?.openpaasId);
|
||||
const saved = sessionStorage.getItem("redirectState")
|
||||
? JSON.parse(sessionStorage.getItem("redirectState")!)
|
||||
: null;
|
||||
@@ -28,6 +26,7 @@ export function CallbackResume() {
|
||||
dispatch(getCalendarsListAsync(data?.tokenSet.access_token ?? ""));
|
||||
|
||||
sessionStorage.removeItem("redirectState");
|
||||
sessionStorage.setItem("tokenSet", JSON.stringify(data?.tokenSet));
|
||||
// Redirect to main page after successful callback
|
||||
dispatch(push("/"));
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
export default async function getOpenPaasUserId(opaque_token: string) {
|
||||
const response = await fetch(
|
||||
`${(window as any).CALENDAR_BASE_URL}/api/user`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${opaque_token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
const user = await response.json();
|
||||
import { api } from "../../utils/apiUtils";
|
||||
|
||||
export default async function getOpenPaasUserId() {
|
||||
const user = await api.get(`api/user`).json();
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||
import { userData, userOrganiser } from "./userDataTypes";
|
||||
import getOpenPaasUserId from "./userAPI";
|
||||
|
||||
export const getOpenPaasUserIdAsync = createAsyncThunk<
|
||||
string, // Return type
|
||||
string // Arg type
|
||||
>("user/getOpenPaasUserId", async (access_token) => {
|
||||
const user = await getOpenPaasUserId(access_token);
|
||||
export const getOpenPaasUserIdAsync = createAsyncThunk<string>(
|
||||
"user/getOpenPaasUserId",
|
||||
async () => {
|
||||
const user = (await getOpenPaasUserId()) as Record<string, string>;
|
||||
|
||||
return user.id;
|
||||
});
|
||||
return user.id;
|
||||
}
|
||||
);
|
||||
|
||||
export const userSlice = createSlice({
|
||||
name: "user",
|
||||
|
||||
Reference in New Issue
Block a user