-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from School-of-Company/update/accessToken-role
🔀 역할 검증 로직 개선
- Loading branch information
Showing
10 changed files
with
54 additions
and
73 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,7 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const role = request.headers.get('role') || 'user'; | ||
|
||
return NextResponse.json({ role }); | ||
} |
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
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,24 @@ | ||
import { NextResponse } from 'next/server'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
export function middleware(request: NextRequest) { | ||
const accessToken = request.cookies.get('accessToken'); | ||
|
||
const requestHeaders = new Headers(request.headers); | ||
|
||
if (accessToken) { | ||
requestHeaders.set('role', 'manage'); | ||
} else { | ||
requestHeaders.set('role', 'user'); | ||
} | ||
|
||
return NextResponse.next({ | ||
request: { | ||
headers: requestHeaders, | ||
}, | ||
}); | ||
} | ||
|
||
export const config = { | ||
matcher: ['/api/role'], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use client'; | ||
|
||
import { useState, useEffect } from 'react'; | ||
|
||
export const useRole = () => { | ||
const [role, setRole] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchRole = async () => { | ||
const response = await fetch('/api/role'); | ||
const data = await response.json(); | ||
setRole(data.role); | ||
}; | ||
|
||
fetchRole(); | ||
}, []); | ||
|
||
return role; | ||
}; |
File renamed without changes.
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
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