Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback done #1

Open
wants to merge 4 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET= # Linux: `openssl rand -hex 32` or go to https://generate-secret.now.sh/32
// verstehe die Zeile hier drüber noch nicht
NEXTAUTH_SECRET=

AUTH0_ID=
AUTH0_SECRET=
Expand All @@ -21,4 +20,5 @@ GOOGLE_SECRET=
TWITTER_ID=
TWITTER_SECRET=

// brauchen wir hier die Platzhalter für Corbado nicht auch noch?
CORBADO_PROJECT_ID=
CORBADO_API_SECRET=
9 changes: 0 additions & 9 deletions components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ export default function Header() {
<li className={styles.navItem}>
<Link href="/">Home</Link>
</li>
<li className={styles.navItem}>
<Link href="/protected">Protected</Link>
</li>
<li className={styles.navItem}>
<Link href="/api-example">API</Link>
</li>
<li className={styles.navItem}>
<Link href="/admin">Admin</Link>
</li>
<li className={styles.navItem}>
<Link href="/me">Me</Link>
</li>
Expand Down
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module.exports = (phase, { defaultConfig }) => {
return {
...defaultConfig,

reactStrictMode: true,
env: {
CORBADO_PROJECT_ID: process.env.CORBADO_PROJECT_ID,
},
webpack: (config) => {
config.resolve = {
...config.resolve,
Expand Down
30 changes: 30 additions & 0 deletions pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Document, { Html, Head, Main, NextScript } from "next/document";

export default class MyDocument extends Document {
render() {
return (
<Html>
<Head>
<title>NextAuth passkey demo</title>

<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous"
></link>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"
></script>
</Head>

<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
13 changes: 9 additions & 4 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,29 @@ export const authOptions: NextAuthOptions = {
async authorize(cred, req) {
if(cred.provider !== "corbado") return null;

// das ist aus dem Node.js SDK rauskopiert oder?
// weil ggf. kurze Erklärung in den Comments, was hier passiert gut wäre
// Get the token from the cookie
var cbo_short_session = req.headers.cookie.split("; ").find(row => row.startsWith("cbo_short_session"));
var token = cbo_short_session.split("=")[1];

// Get the JWKS URL from the project ID
var issuer = "https://" + projectID + ".frontendapi.corbado.io";
var jwksUrl = issuer + "/.well-known/jwks";

// Initialize the JWKS client
const JWKS = jose.createRemoteJWKSet(new URL(jwksUrl), {
cacheMaxAge: 10 * 60 * 1000
})
const options = {
issuer: issuer,
}
try {

// Verify the token
const {payload} = await jose.jwtVerify(token, JWKS, options)
if (payload.iss === issuer) {
//Load data from database
// Von der User database right?

//
//Next steps: Load data from database here to always have all the data available in the session
return { email: payload.email, name: payload.name, image: null};
}else{
console.log("issuer not valid")
Expand Down
2 changes: 1 addition & 1 deletion pages/api/auth/associate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { NextApiRequest, NextApiResponse } from "next"

// sind nicht im passenden .env Example
const projectID = process.env.CORBADO_PROJECT_ID;
const apiSecret = process.env.API_SECRET;
const apiSecret = process.env.CORBADO_API_SECRET;


export default async function handler(
Expand Down
14 changes: 0 additions & 14 deletions pages/api/examples/jwt.ts

This file was deleted.

22 changes: 0 additions & 22 deletions pages/api/examples/protected.ts

This file was deleted.

13 changes: 0 additions & 13 deletions pages/api/examples/session.ts

This file was deleted.

4 changes: 0 additions & 4 deletions pages/auth/redirect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { getProviders, signIn } from "next-auth/react"
import { getServerSession } from "next-auth/next"
import { authOptions } from "../api/auth/[...nextauth]";

// bitte über zentrale .env File beziehen
const projectID = "pro-2808756695548043260";
console.log("Project ID: ", projectID)


export default function Redirect(
{ providers }: InferGetServerSidePropsType<typeof getServerSideProps>, req: NextApiRequest,
Expand Down
28 changes: 15 additions & 13 deletions pages/auth/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useCallback, useEffect, useState } from "react";

import '@corbado/webcomponent/pkg/auth_cui.css'

const projectID = process.env.CORBADO_PROJECT_ID;

export default function SignIn(
{ providers }: InferGetServerSidePropsType<typeof getServerSideProps>, req: NextApiRequest,
res: NextApiResponse) {
Expand All @@ -27,12 +29,10 @@ export default function SignIn(
.then(module => {
const Corbado = module.default || module;

console.log("Initializing Corbado session")
// bitte über .env File beziehen
setSession(new Corbado.Session("pro-2808756695548043260"));
("Initializing Corbado session")
setSession(new Corbado.Session(projectID));
})
.catch(err => {
console.log(err);
});
}, [])

Expand All @@ -46,9 +46,6 @@ export default function SignIn(

return (
<>
{/*das nicht in einen zentralen Header packen?*/}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"></link>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<div className="parent">
<div className="buttons">
{providersNew.map((provider) => (
Expand All @@ -59,12 +56,10 @@ export default function SignIn(
</div>
))}
</div>
<div>
{/*aus .env File holen*/}
<corbado-auth project-id="pro-2808756695548043260" conditional="yes">
<input name="username" id="corbado-username"
required autoComplete="webauthn"/>
</corbado-auth>
<div className="associate-container">

<corbado-passkey-associate-login
project-id={projectID}/>
</div>
</div>
<style jsx>{`
Expand All @@ -85,6 +80,13 @@ export default function SignIn(
border-radius: 30px;
background-color: #1853FE;
}

.associate-container {
width: 200px;
margin-left: auto;
margin-right: auto;
align-items: center;
}
`}</style>
</>
)
Expand Down