-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added OAuth, CosmosDB, & Markdown Rendering
- Loading branch information
Showing
16 changed files
with
1,403 additions
and
173 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
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 |
---|---|---|
@@ -1,6 +1,59 @@ | ||
"use client"; | ||
import { useState } from "react"; | ||
|
||
export default function Course({ params }: { params: { courseName: string } }) { | ||
return <div className="flex">course {params.courseName} Home </div>; | ||
import React from "react"; | ||
const { BlockBlobClient } = require("@azure/storage-blob"); | ||
import ReactMarkdown from "react-markdown"; | ||
|
||
async function getSASurl(courseName: string) { | ||
let res = await fetch( | ||
"http://localhost:3000/api/" + | ||
courseName + | ||
"/getSAS?filename=readme/syllabus.md", | ||
{ | ||
method: "GET", | ||
} | ||
); | ||
|
||
if (!res.ok) { | ||
throw new Error("Failed to fetch data"); | ||
} | ||
let sasURL = await res.json(); | ||
return sasURL.sasURL; | ||
} | ||
|
||
// Convert stream to text | ||
async function streamToText(readable: any) { | ||
readable.setEncoding("utf8"); | ||
let data = ""; | ||
for await (const chunk of readable) { | ||
data += chunk; | ||
} | ||
return data; | ||
} | ||
|
||
// Download the blob content | ||
async function getHomePage(courseName: string) { | ||
const sasURL: string = await getSASurl(courseName); | ||
const blockBlobClient = new BlockBlobClient(sasURL); | ||
|
||
const downloadBlockBlobResponse = await blockBlobClient.download(0); | ||
const downloaded = await streamToText( | ||
await downloadBlockBlobResponse.readableStreamBody | ||
); | ||
return downloaded; | ||
} | ||
|
||
export default async function Course({ | ||
params, | ||
}: { | ||
params: { courseName: string }; | ||
}) { | ||
// const content = await getHomePage(params.courseName); FETCH DISABLED WHILE DEVELOPING | ||
|
||
return ( | ||
<div> | ||
{/* <ReactMarkdown className="prose" children={content} /> FETCH DISABLED WHILE DEVELOPING*/} | ||
<h1>Course {params.courseName}</h1> | ||
</div> | ||
); | ||
} |
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
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,3 @@ | ||
import { handlers } from "@/auth"; | ||
|
||
export const { GET, POST } = handlers; |
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,23 +1,15 @@ | ||
"use client"; | ||
import { useRouter } from "next/navigation"; | ||
import Navbar from "./components/Navbar"; | ||
import { useEffect, useState } from "react"; | ||
import { useUserContext } from "./context/userContext"; | ||
import { auth } from "@/auth"; | ||
import { redirect } from "next/navigation"; | ||
|
||
export default function Home() { | ||
export default async function Home() { | ||
// const { userId, setUserId, courseList, setCourseList } = useUserContext(); | ||
//this will be sent to navbar by using useContext | ||
|
||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
// user is not logged in | ||
router.push("/login"); | ||
}, [router]); | ||
|
||
return ( | ||
<div className="flex"> | ||
<button>Home</button> | ||
</div> | ||
); | ||
const session = await auth(); | ||
if (!session) { | ||
redirect("/api/auth/signin?callbackUrl=/dashboard"); | ||
return null; | ||
} else { | ||
redirect("/dashboard"); | ||
} | ||
} |
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,32 @@ | ||
import NextAuth from "next-auth"; | ||
import GithubProvider from "next-auth/providers/github"; | ||
import PostgresAdapter from "@auth/pg-adapter"; | ||
const { Pool } = require("pg"); | ||
|
||
// Store user accounts in CosmosDB Postgres as well | ||
const pool = new Pool({ | ||
max: 300, | ||
connectionTimeoutMillis: 5000, | ||
host: process.env.AZURE_COSMOSDB_PG_URL, | ||
port: 5432, | ||
user: process.env.AZURE_COSMOSDB_PG_USER, | ||
password: process.env.AZURE_COSMOSDB_PG_PASSWORD, | ||
database: process.env.AZURE_COSMOSDB_PG_DBNAME, | ||
ssl: true, | ||
}); | ||
|
||
export const { handlers, auth } = NextAuth({ | ||
adapter: PostgresAdapter(pool), | ||
providers: [ | ||
GithubProvider({ | ||
clientId: process.env.GITHUB_ID, | ||
clientSecret: process.env.GITHUB_SECRET, | ||
}), | ||
], | ||
callbacks: { | ||
async session({ session, user }) { | ||
session.user.id = user.id; | ||
return session; | ||
}, | ||
}, | ||
}); |
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.