Skip to content

Admin Token Fix #167

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

Open
wants to merge 2 commits into
base: main
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
2 changes: 1 addition & 1 deletion client/src/pages/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function Profile() {

try {
await fetchWithAuth({
url: `${HOST}/api/profile/get/${user.profileId}`,
url: `${HOST}/api/profile/${user.profileId}`,
method: 'PATCH',
data: updatedProfile,
})
Expand Down
21 changes: 18 additions & 3 deletions client/src/util/tokenUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ import Cookies from 'js-cookie'
import { HOST } from './apiRoutes'

export const generateToken = async () => {
const linkedinToken = localStorage.getItem('linkedinToken')
const adminToken = localStorage.getItem('adminToken')
const tokenKeys = ['linkedin', 'admin']
const tokenQueries = []

// loop through tokens needed and fetch them
for (const tokenKey of tokenKeys) {
const tokenName = `${tokenKey}Token`
const token = localStorage.getItem(tokenName)

// if the token exists, add it to the token pieces
if (token) {
tokenQueries.push(`${tokenName}=${token}`)
}
}

// Construct the URL dynamically based on the tokens array
const tokenParams =
tokenQueries.length > 0 ? '?' + tokenQueries.join('&') : ''
const url = `${HOST}/api/token${tokenParams}`

// Use fetch to get a new session ID if one does not already exist
try {
const url = `${HOST}/api/token${linkedinToken ? `?linkedinToken=${linkedinToken}` : ''}${adminToken ? `&adminToken=${adminToken}` : ''}`
const response = await fetch(url)

if (!response.ok) {
Expand Down