这是我的getServerSideProps代码:
//@ts-ignore
export async function getServerSideProps({ req, res, query }) {
const { id } = query
const cookies = Cookies(req, res)
const jwt = cookies.get('lit-auth')
if (!jwt) {
return {
props: {
authorized: false
},
}
}
const { verified, payload } = LitJsSdk.verifyJwt({ jwt })
console.log(verified)
console.log(payload)
if (
payload.baseUrl !== "http://localhost:3000"
|| payload.path !== '/protected'
|| payload.extraData !== id
) {
return {
props: {
authorized: false
},
}
}
storePersistence(payload)
return {
props: {
authorized: verified ? true : false
},
}
}
function storePersistence(payload: string) {
window.localStorage.set我tem('lit_protocols_jwt', payload);
}
我
This is the error 我 get in my console
error - src/pages/protected.tsx (199:2) @ storePersistence
ReferenceError: window is not defined
197 |
198 | function storePersistence(payload: string) {
> 199 | window.localStorage.set我tem('lit_protocols_jwt', payload);
| ^
200 | }
201 |
How can 我 store payload
persistently in the client's browser? 我'd be willing to try some other method if you can think of one but 我 need the client's browser to retain payload
for future access.