ADD: added basic backend function plus a mockup for a cli interface
This commit is contained in:
23
frontend/studia/src/utils/jwt.tsx
Normal file
23
frontend/studia/src/utils/jwt.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
// utils/jwt.ts
|
||||
import { jwtDecode } from 'jwt-decode';
|
||||
|
||||
export interface TokenPayload {
|
||||
userId: string;
|
||||
email: string;
|
||||
role: string[];
|
||||
exp: number;
|
||||
}
|
||||
|
||||
export function getUserFromToken(token: string): TokenPayload | null {
|
||||
try {
|
||||
const decoded = jwtDecode<TokenPayload>(token);
|
||||
if (decoded.exp && decoded.exp < Date.now() / 1000) {
|
||||
console.warn("Token ist abgelaufen");
|
||||
return null;
|
||||
}
|
||||
return decoded;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Decodieren des Tokens:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user