create-miro-app
Version:
Create Miro app
37 lines (32 loc) • 720 B
text/typescript
import {Miro} from '@mirohq/miro-api';
import {Request, Response, NextFunction} from 'express';
// define miro object on request
declare global {
namespace Express {
interface Request {
miro: Miro;
}
}
}
export default function middlware(
req: Request,
res: Response,
next: NextFunction,
) {
req.miro = new Miro({
storage: {
async get(_userId) {
try {
return JSON.parse(req.cookies.state);
} catch (err) {
return undefined;
}
},
set(userId, state) {
res.cookie('id', userId, {path: '/', secure: true});
res.cookie('state', JSON.stringify(state), {path: '/', secure: true});
},
},
});
next();
}