Skip to content

Commit

Permalink
fix: revert to server actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew committed Jul 10, 2024
1 parent 438c82d commit 43035cd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/hooks/contexts/useHeadlessAIS.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client";;
"use client";
import {HeadlessAISStorage, LoginError, UserJWT} from '@/types/headless_ais';
import { toast } from "@/components/ui/use-toast";
import { FC, PropsWithChildren, createContext, useContext, useEffect, useState } from "react";
import { useLocalStorage } from 'usehooks-ts';
import useDictionary from "@/dictionaries/useDictionary";
import { useCookies } from "react-cookie";
import {fetchRefreshUserSession, fetchSignInToCCXP} from '@/helpers/headless_ais';
import { decodeJwt } from 'jose';
import { refreshUserSession, signInToCCXP } from '@/lib/headless_ais';
const headlessAISContext = createContext<ReturnType<typeof useHeadlessAISProvider>>({
user: undefined,
ais: {
Expand All @@ -27,7 +27,7 @@ const useHeadlessAISProvider = () => {
const [initializing, setInitializing] = useState(true);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<LoginError | undefined>(undefined);
const [cookies, setCookies, removeCookies, updateCookies] = useCookies(['accessToken']);
const [cookies, removeCookies] = useCookies(['accessToken']);
const dict = useDictionary();

useEffect(() => { setInitializing(false) }, []);
Expand Down Expand Up @@ -56,7 +56,7 @@ const useHeadlessAISProvider = () => {
return ;
}
setLoading(true);
return await fetchSignInToCCXP(username, password)
return await signInToCCXP(username, password)
.then((res) => {
if(!res) throw new Error("太多人在使用代理登入,請稍後再試");
if('error' in res) throw new Error(res.error.message);
Expand Down Expand Up @@ -108,7 +108,7 @@ const useHeadlessAISProvider = () => {
// legacy support, if encrypted password is not set, set it
if(!headlessAIS.encrypted) {
// use signInToCCXP to get encrypted password
return await fetchSignInToCCXP(headlessAIS.studentid, headlessAIS.password)
return await signInToCCXP(headlessAIS.studentid, headlessAIS.password)
.then((res) => {
if('error' in res) throw new Error(res.error.message);
setHeadlessAIS({
Expand All @@ -125,7 +125,7 @@ const useHeadlessAISProvider = () => {
})
}

return await fetchRefreshUserSession(headlessAIS.studentid, headlessAIS.password)
return await refreshUserSession(headlessAIS.studentid, headlessAIS.password)
.then((res) => {
if('error' in res) throw new Error(res.error.message);
setHeadlessAIS({
Expand Down

0 comments on commit 43035cd

Please sign in to comment.