userfront-core icon indicating copy to clipboard operation
userfront-core copied to clipboard

Add custom token getters and setters

Open tyrw opened this issue 4 years ago • 0 comments

Right now, tokens are set automatically and can be read with e.g. Userfront.tokens.accessToken. However, this assumes a browser context, so does not work with many SSR applications.

It would be good to have a way to specify getter and setter methods for the tokens, so that SSR applications can still use the library.

Potential API (nextjs example):

import Cookies from 'cookies'

Homepage.getInitialProps = ({ req, res }) => {
    const cookies = new Cookies(req, res);
 
    Userfront.tokens.getter = cookies.get
    Userfront.tokens.setter = (name, value, options) => cookies.set(name, value, options)
}

tyrw avatar Jan 03 '22 17:01 tyrw