Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('with redirections.', async () => {
@Entity()
class User extends UserWithPermissions {
@Column({ unique: true })
email: string;
@Column()
password: string;
}
@TokenRequired({ user: fetchUserWithPermissions(User), store: TypeORMStore, cookie: true })
class MyController {
@Get('/foo')
foo() {
return new HttpResponseOK();
}
@Get('/bar')
@PermissionRequired('admin')
bar() {
return new HttpResponseOK();
}
}
class AuthController {
@dependency
store: TypeORMStore;
it('Authentication and authorization', async () => {
@Entity()
class User extends UserWithPermissions {
@Column({ unique: true })
email: string;
@Column()
password: string;
}
@LoginRequired({ user: fetchUserWithPermissions(User) })
class MyController {
@Get('/foo')
foo() {
return new HttpResponseOK();
}
@Get('/bar')
@PermissionRequired('admin')
bar() {
return new HttpResponseOK();
}
}
class AuthController {
@Get('/logout')
logout(ctx: Context) {
describe('[Authorization|permissions] Users', () => {
let app;
let tokenUser1: string;
let tokenUser2: string;
@Entity()
class User extends UserWithPermissions {}
@TokenRequired({ user: fetchUserWithPermissions(User), store: TypeORMStore })
class AppController {
@Get('/bar')
@PermissionRequired('access-bar')
bar() {
return new HttpResponseNoContent();
}
@Get('/foo')
@PermissionRequired('access-foo')
foo() {
return new HttpResponseNoContent();
}
}
before(async () => {
process.env.SETTINGS_SESSION_SECRET = 'session-secret';
import { Context, Get, LoginRequired, render } from '@foal/core';
import { fetchUserWithPermissions, PermissionRequired } from '@foal/typeorm';
import { User } from '../entities';
@LoginRequired({ user: fetchUserWithPermissions(User), redirect: '/login' })
export class ViewController {
@Get('/')
home(ctx: Context) {
return render('./templates/home.html', {
csrfToken: ctx.request.csrfToken()
}, __dirname);
}
@Get('/admin')
@PermissionRequired('admin', { redirect: '/login' })
admin(ctx: Context) {
return render('./templates/admin.html', {
csrfToken: ctx.request.csrfToken()
}, __dirname);
}