Get Token
Get JSON Web Token from the current user session.
Use the next code lines to retrieve a valid JWT, we already handle refresh tokens, so you always get a valid token.
src/home.tsx
import { useNxWhatsAppContext } from "@nuveraxgroup/widget";
import { useEffect, useState } from "react";
export const Home = () => {
const [token, setToken] = useState<string | null>(null);
const { getToken } = useNxWhatsAppContext();
useEffect(() => {
getToken("{ADD_YOUR_APP_ID}").then((t) => setToken(t));
}, []);
return (
<>
<h1>Secured context</h1>
<h2>Welcome</h2>
{token !== null && <pre>{token}</pre>}
</>
);
}
info
Replace {ADD_YOUR_APP_ID} placeholder with your app id.
warning
The next hook useNxWhatsAppContext() depends on <NxWhatsApp/> tag context,
please make sure to add this tag context as parent tag.
Follow the next documentation to know how.
For an advanced example please check the next code example.
Token Payload
| Property | Description |
|---|---|
exp | Expiration time of the JWT (24 hours by default). |
iat | Creatiion time of the JWT. |
sub | User account Id. |
env | Environment of the JWT (It could be production or development). |
aud | Programmable OTP application id. |
iss | The issuer of the JWT (https://wa.nuverax.com by default). |
nonce | Nonce value previously generated by the client application. |
session_exp | Access token expiration (2h by default), it restarts expiration if we refresh tokens, you can do rolling session up to 24h. |
jti | Access token id. |
p_hash | Phone number hash (SHA-256 of the registered phone number including country code). For example country_code=52 and phone_number=5512345678 the final phone number is 525512345678 so the SHA-256 is 8f9d0944329b5338c6fb86f293ceb39385b596254748dd3628ec62f55c334811 |