Skip to content

Commit

Permalink
Get bearer token and push it in API request (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
demanguillaume authored Jun 25, 2024
1 parent b17a506 commit fc26b54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app/apiClient/registerUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const registerUserApi = async (data: {
email: string;
password: string;
confirmPassword: string;
username: string;
name: string;
lastName: string;
Expand Down
18 changes: 15 additions & 3 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { withAuth } from "next-auth/middleware";
import { NextRequestWithAuth, withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";

export default withAuth(
function middleware(req) {
async function middleware(req: NextRequestWithAuth) {
// ajouter les informations de la session à la requête ?
return NextResponse.next();
const bearerToken = req.headers.get("Authorization");
const token = bearerToken?.split("Bearer ")[1];

console.log("middleware token", token);

const requestHeaders = new Headers(req.headers);
requestHeaders.set("Authorization", `Bearer ${token}`);

return NextResponse.next({
request: {
headers: requestHeaders,
},
});
},
{
callbacks: {
Expand Down

0 comments on commit fc26b54

Please sign in to comment.