-
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 #16 from avantifellows/feature/auth-flow
Fetch user details from token
- Loading branch information
Showing
11 changed files
with
194 additions
and
135 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,27 @@ | ||
"use server" | ||
|
||
import axios from 'axios'; | ||
import getAxiosConfig from '../axiosConfig'; | ||
import { User } from '@/app/types'; | ||
|
||
export const getUserName = async (studentId: string): Promise<User | null> => { | ||
const url = process.env.AF_DB_SERVICE_URL; | ||
const bearerToken = process.env.AF_DB_SERVICE_BEARER_TOKEN!; | ||
|
||
try { | ||
const response = await axios.get(`${url}/student`, { | ||
params: { student_id: studentId }, | ||
...getAxiosConfig(bearerToken), | ||
}); | ||
|
||
if (response.data.length === 0) { | ||
console.warn(`No user found for student ID: ${studentId}`); | ||
return null; | ||
} | ||
|
||
return response.data[0].user; | ||
} catch (error) { | ||
console.error('Error fetching student data:', error); | ||
throw error; | ||
} | ||
} |
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
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
Oops, something went wrong.