-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track selection form and fetching of init data
- Loading branch information
Showing
9 changed files
with
341 additions
and
174 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,45 @@ | ||
/** | ||
* Offer an endpoint to call in order to request a track list positions. This will | ||
* read the auth token from the cookie, so we don't need to access it on the client | ||
*/ | ||
|
||
import { AuthenticationRequest, AuthenticationResponse } from "@/lib/api.website"; | ||
import {getTrackList, getVehicleData} from "@/lib/data"; | ||
import { STATUS_CODES } from "http"; | ||
import { redirect } from "next/dist/server/api-utils"; | ||
import { cookies } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import {UnauthorizedError} from "@/lib/types"; | ||
|
||
export async function GET(request: NextRequest) { | ||
// console.log("foobar", request) | ||
const token = cookies().get("token")?.value; | ||
// console.log("requested track_id", track_id); | ||
|
||
if (token) { | ||
try { | ||
const tracks = await getTrackList(token); | ||
// console.log("vehicles", vehicles) | ||
return NextResponse.json(tracks) | ||
} | ||
catch (e: any) { | ||
if (e instanceof UnauthorizedError) { | ||
// token may have expired. Delete token. | ||
cookies().set({ | ||
name: 'token', | ||
value: '', | ||
sameSite: 'lax', | ||
httpOnly: true, | ||
expires: new Date(0) | ||
}) | ||
console.log('UnauthorizedError') | ||
return new NextResponse('Unauthorized', {status: 401}) | ||
} else | ||
return new NextResponse("Error" + e.toString(), {status: 500}) | ||
} | ||
} | ||
else { | ||
return new NextResponse("Unauthorized", {status: 401}) | ||
} | ||
|
||
} |
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
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
Empty file.
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
Oops, something went wrong.