N
Nuxt6mo ago
Nossie

JsonToken

Oke so im trying to implement a video player that can only be accessed when having a jsonwebtoken currently i have this code ( and its working )
const payload:JWTPayload = {
"iat" : Math.floor(Date.now() / 1000),
"sub": id as string,
"iss": 'company-name',
}

const secret = 'jwt-secret-overhere';
const alg = 'HS256';

key.value = new TextEncoder().encode(secret)

token.value = await new jose.SignJWT(payload)
.setProtectedHeader({ alg })
.setIssuedAt()
.sign(key.value)



onMounted(()=> {
if(import.meta.client) {
const playerContainer = document.body.querySelector('.player') as HTMLElement;
if(playerContainer) {
const player = new $Player(playerContainer, playerConfig);

player.loadStream(token.value, streamConfiguration);

}

}
})
const payload:JWTPayload = {
"iat" : Math.floor(Date.now() / 1000),
"sub": id as string,
"iss": 'company-name',
}

const secret = 'jwt-secret-overhere';
const alg = 'HS256';

key.value = new TextEncoder().encode(secret)

token.value = await new jose.SignJWT(payload)
.setProtectedHeader({ alg })
.setIssuedAt()
.sign(key.value)



onMounted(()=> {
if(import.meta.client) {
const playerContainer = document.body.querySelector('.player') as HTMLElement;
if(playerContainer) {
const player = new $Player(playerContainer, playerConfig);

player.loadStream(token.value, streamConfiguration);

}

}
})
The only thing is i dont want the secret of my jjwt in side client, i already tried to move this to the env file , but for some reason i doesnt work anymore , ( if i log the config.jwtSecret from env) i see the secret in terminal. but the whole signing doestn work anymore does someone has a solution to help me out putting my secrete not client side
1 Reply
Nossie
NossieOP6mo ago
nvm figured it out with state management
Want results from more Discord servers?
Add your server