productdevbook
12/13/2022, 5:22 AMrp_st
12/13/2022, 5:37 AMrp_st
12/13/2022, 5:37 AMproductdevbook
12/13/2022, 5:37 AMrp_st
12/13/2022, 5:37 AMSession.getAccessTokenPayloadSecurely
functionrp_st
12/13/2022, 5:38 AMproductdevbook
12/13/2022, 5:39 AMts
import {
ApolloClient,
InMemoryCache,
createHttpLink,
} from '@apollo/client/core/index.js'
import {
DefaultApolloClient,
provideApolloClient,
} from '@vue/apollo-composable/dist/index.esm.js'
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin((nuxtApp) => {
const a = useCookie('sAccessToken')
// console.log(a.value, 'aaa')
const httpLink = createHttpLink({
credentials: 'include',
uri: 'http://127.0.0.1:3001/graphql',
headers: {
authorization: `Bearer ${a.value}`,
},
})
const cache = new InMemoryCache()
let apolloClient: ApolloClient<any>
if (process.server) {
apolloClient = new ApolloClient({
ssrMode: true,
link: httpLink,
cache,
})
nuxtApp.hook('app:rendered', () => {
nuxtApp.payload.data.apollo = apolloClient.extract()
})
}
else {
apolloClient = new ApolloClient({
link: httpLink,
cache,
ssrForceFetchDelay: 100,
})
}
nuxtApp.hook('app:rendered', () => {
if (process.server)
nuxtApp.payload.apollo = apolloClient.cache.extract()
})
provideApolloClient(apolloClient)
nuxtApp.provide('$apollo', { DefaultApolloClient, apolloClient })
})
productdevbook
12/13/2022, 5:39 AMrp_st
12/13/2022, 5:41 AMauthorization
headers at all if the graphql layer is in the same apiDomain as the supertokens APIrp_st
12/13/2022, 5:41 AMauthorization
headerproductdevbook
12/13/2022, 6:48 AMts
Session.init({
jwt: {
enable: true,
issuer: 'http://localhost:3001/auth',
propertyNameInAccessTokenPayload: 'session',
},
}), // initializes session features
thats truerp_st
12/13/2022, 6:49 AMproductdevbook
12/13/2022, 6:49 AMrp_st
12/13/2022, 6:49 AMrp_st
12/13/2022, 6:49 AMproductdevbook
12/13/2022, 6:49 AMproductdevbook
12/13/2022, 6:49 AMproductdevbook
12/13/2022, 6:51 AMconst ab = await Session.getAccessTokenPayloadSecurely()
if (ab.session)
token = ab.session
No instance of Session found. Make sure to call the Session.init method. If you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook.productdevbook
12/13/2022, 6:51 AMts
nuxtApp.hook('app:suspense:resolve', async () => {
const ab = await Session.getAccessTokenPayloadSecurely()
if (ab.session)
token = ab.session
})
If I use it like that, I can't get the token on the ssr siderp_st
12/13/2022, 6:54 AMrp_st
12/13/2022, 6:54 AMab.session
is wrong. It should be ab.jwt
- please see the docsproductdevbook
12/13/2022, 6:54 AMproductdevbook
12/13/2022, 6:54 AMrp_st
12/13/2022, 6:54 AMab.jwt
rp_st
12/13/2022, 6:54 AM