Skip to content

Commit

Permalink
BREAKING: move back to server actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustChew committed Jul 29, 2024
1 parent 49cc7e7 commit db7aebc
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 70 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"jsdom": "^24.1.0",
"jsonwebtoken": "^9.0.2",
"leaflet": "^1.9.4",
"linkedom": "^0.18.3",
"linkedom": "^0.18.4",
"lucide-react": "^0.383.0",
"negotiator": "^0.6.3",
"next": "^14.2.4",
Expand Down
11 changes: 1 addition & 10 deletions src/app/[lang]/(mods-pages)/student/grades/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ const StudentGradesPage = () => {
queryFn: async () => {
if(initializing) return null;
const token = await getACIXSTORE();
// return (await getStudentGrades(token!)) as GradeObject;
return await fetch('/api/ais_auth/grades', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
ACIXSTORE: token
})
}).then(res => res.json()) as GradeObject
return (await getStudentGrades(token!)) as GradeObject;
}
});
if (!ais.enabled) return <AISNotLoggedIn/>
Expand Down
14 changes: 0 additions & 14 deletions src/app/api/ais_auth/grades/route.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/app/api/ais_auth/refresh/route.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/app/api/ais_auth/signin/route.ts

This file was deleted.

10 changes: 5 additions & 5 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 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 db7aebc

Please sign in to comment.