Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Authenticate controller
import { Context, dependency, Get, render, TokenRequired } from '@foal/core';
import * as React from 'react';
import * as ReactDOMServer from 'react-dom/server';
import { User } from '../entities';
import { TypeORMStore } from '@foal/typeorm';
export class ViewController {
@dependency
store: TypeORMStore;
@Get('/test2')
@TokenRequired({ store: this.store, cookie: true })
async test2(context: Context<User>) {
if(context.request.cookies['sessionID']) {
const session = await this.store.read(context.request.cookies['sessionID']);
if(session)
console.log(session.getToken());
}
return render('./templates/index.html', {
content: ReactDOMServer.renderToString(<div>{context.request.cookies['sessionID']}</div>),
});
}
}
@pettomartino
Copy link
Author

pettomartino commented Dec 16, 2019

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment