Skip to content

Instantly share code, notes, and snippets.

@slauzinho
Created July 19, 2022 15:42
Show Gist options
  • Save slauzinho/7f251917bfbd11f9ee2ec0e02967ef01 to your computer and use it in GitHub Desktop.
Save slauzinho/7f251917bfbd11f9ee2ec0e02967ef01 to your computer and use it in GitHub Desktop.
<script setup lang="ts">
import jwtDecode from "jwt-decode";
const token =
"eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJkdXJnYSIsImV4cCI6MTY1OTk1NTI4NSwiaWF0IjoxNjU3NTM2MDg1LCJpc3MiOiJkdXJnYSIsImp0aSI6IjI2OTk1NWQyLTQwMzAtNGFkZS05YTgxLTg5MDg0NjQ1NTQwZSIsIm5iZiI6MTY1NzUzNjA4NCwic3ViIjoiMiIsInR5cCI6ImFjY2VzcyJ9.qWI5umsmYubVu1bSvje-nT9gUSi0PphsPnyWiY8_PDTYHHF-ATSNvsD2hZpUad7AgluUE-i1S103-GYiKkf6Ag";
interface JWTPayload {
aud: string;
exp: number;
iat: number;
iss: string;
jti: string;
nbf: number;
sub: string;
type: string;
}
const decoded = jwtDecode<JWTPayload>(token);
console.log(`decoded:`, decoded.sub);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment