-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move headless ais behind api routes (#365)
- Loading branch information
Showing
4 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { refreshUserSession, signInToCCXP } from "@/lib/headless_ais"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const POST = async (req: NextRequest) => { | ||
const form = await req.formData(); | ||
const studentid = form.get("studentid"); | ||
const encryptedPassword = form.get("encryptedPassword"); | ||
|
||
if(!studentid || !encryptedPassword) return NextResponse.json({ error: { message: "Missing Student ID and Password" }}, { status: 400 }) | ||
|
||
return NextResponse.json(await refreshUserSession(studentid as string, encryptedPassword as string)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { signInToCCXP } from "@/lib/headless_ais"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const POST = async (req: NextRequest) => { | ||
const form = await req.formData(); | ||
const studentid = form.get("studentid"); | ||
const password = form.get("password"); | ||
|
||
if(!studentid || !password) return NextResponse.json({ error: { message: "Missing Student ID and Password" }}, { status: 400 }) | ||
|
||
return NextResponse.json(await signInToCCXP(studentid as string, password as string)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// This is a temporary workaround to get headless ais to work | ||
// as current server actions are failing | ||
|
||
import type { signInToCCXP } from "@/lib/headless_ais"; | ||
import type { refreshUserSession } from "@/lib/headless_ais"; | ||
|
||
export const fetchSignInToCCXP = async (studentid: string, password: string) => { | ||
const form = new FormData(); | ||
form.append("studentid", studentid); | ||
form.append("password", password); | ||
const res = await fetch('/api/ais_auth/signin', { | ||
method: 'POST', | ||
body: form | ||
}); | ||
return await res.json() as ReturnType<Awaited<typeof signInToCCXP>>; | ||
} | ||
|
||
export const fetchRefreshUserSession = async (studentid: string, encryptedPassword: string) => { | ||
const form = new FormData(); | ||
form.append("studentid", studentid); | ||
form.append("encryptedPassword", encryptedPassword); | ||
const res = await fetch('/api/ais_auth/refresh', { | ||
method: 'POST', | ||
body: form | ||
}); | ||
return await res.json() as ReturnType<Awaited<typeof refreshUserSession>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters