I´m using the static Token for authenticated Queries. With logging in i want to save the Static Token within the session, but I can´t find a way to decrypt the Token. I´m saving the Token in the session already, but i´m just getting ****** as a value.
I tried to decrypt it with jwt decode, but the Token doesn´t seem to be in the correct jwt Format.
This is my current Code:
import { getServerSession } from "next-auth";
import { options } from "./[...nextauth]/options";
import { readItems } from "@directus/sdk";
import directus from "../../../../lib/directus";
import { jwtDecode } from "jwt-decode";
import { decode } from "next-auth/jwt";
export async function getUserInfo() {
const session = await getServerSession(options);
let userId = '';
let isAdmin = false;
let isActiveSession = false;
let isUserActive = false;
let isUserRejected = false;
let isUserBlocked = false;
let accessToken = null;
let userMainToken = null;
if (session && session.user && session.user.id && session.user.id.id) {
userId = session.user.id.id;
const userMainToken = session.user.id.token;
}
const res = await fetch(`*********/users/${userId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${userMainToken}`,
}
});
const resTemp = await res.json();
const userContent = resTemp.data;
const adminID = 'e2895cd6-42e0-450f-9690-9b140572548e';
if (userContent?.role === adminID) {
isAdmin = true;
}
if (session) {
isActiveSession = true;
}
if(userContent?.aktiver_nutzer) {
isUserActive = true;
}
return { userId, isAdmin, userContent, isActiveSession, isUserActive, accessToken };
}