Jwt

Wrapper for

jwt-decode
.

⚡️ Prerequisites

npm install --save jwt-decode
npm install --save jwt-decode
sh

Usage

<script>
    import {jwt} from "@sveu/extend/jwt"

    const { header, payload } = jwt("your-token")

    console.log(header)

    console.log(payload)
</script>
<script>
    import {jwt} from "@sveu/extend/jwt"

    const { header, payload } = jwt("your-token")

    console.log(header)

    console.log(payload)
</script>
svelte

Example

Header:

{"alg":"HS256","typ":"JWT"}


Payload:

{"sub":"1234567890","name":"John Doe","iat":1516239022}

<script>
    import { jwt } from "@sveu/extend/jwt" 

    let token =
        "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"

    $: ({ header, payload } = jwt(token)) 
</script>

<input bind:value="{token}" />

<h1>Header:</h1>
<h2>{JSON.stringify(header)}</h2>

<hr />

<h1>Payload:</h1>
<h2>{JSON.stringify(payload)}</h2>
<script>
    import { jwt } from "@sveu/extend/jwt" 

    let token =
        "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"

    $: ({ header, payload } = jwt(token)) 
</script>

<input bind:value="{token}" />

<h1>Header:</h1>
<h2>{JSON.stringify(header)}</h2>

<hr />

<h1>Payload:</h1>
<h2>{JSON.stringify(payload)}</h2>
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Click fold/expand code

API

Arguments

Name Description Type Required
value JWT string. string Yes


Options

Nam Description Type Default
fallback Value returned when encounter error on decoding. any null
onError Error callback for decoding. (error: unknown) => void undefined