1

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 };
}




1
  • My current Workaround is to pass the generated static token to a normal Textinput which can be queried like any other „normal“ Text-Input field. This works perfect, but obviously isn’t the nicest way (still a workaround) Commented May 29, 2024 at 19:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.