-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSR with oidc-client #5
Comments
Raw answer is: First, you need to implement CookieStorage like this: // CookieStorage.ts
import { Cookies } from 'quasar';
// Attention to this to secure your cookies!
const options = {
sameSite: 'Strict',
secure: true,
path: '/'
};
const encode = encodeURIComponent;
export { Cookies };
export default class CookieStorage
{
private cookies: Cookies;
public constructor(cookies: Cookies)
{
this.cookies = cookies;
}
public setItem(key: string, value: any)
{
this.cookies.set(encode(key), value, options);
}
public getItem(key: string)
{
return JSON.stringify(this.cookies.get(encode(key))); //, { doNotParse: true });
}
public removeItem(key: string)
{
this.cookies.remove(encode(key), options);
}
public key(index: number)
{
const allKeys = Object.keys(this.cookies.getAll());
return (index > -1 && index <= allKeys.length) ? allKeys[index] : '';
}
} You need to extract right cookies in your custom boot file, then to override import { WebStorageStateStore } from 'oidc-client';
import CookieStorage, { Cookies } from './CookieStorage';
export function boot(({ ssrContext }) =>
{
const cookies = process.env.SERVER
? Cookies.parseSSR(ssrContext)
: Cookies;
const oidcSettings = {
//
// other settings goes here
//
userStore: new WebStorageStateStore({
store: new CookieStorage(cookies),
//prefix: '' // custom prefix if you like
}),
};
// pass it to new UserManager(oidcSettings);
}); Enjoy! |
@Arsync Thank you for the quick help, it works for me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
How we can store data in quasar cookies instead of local storage for SSR?
The text was updated successfully, but these errors were encountered: