O'Reilly logo

TypeScript: Modern JavaScript Development by Ivo Gabe de Wolff, Vilic Vane, Remo H. Jansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding authentication

In lib/server/index.ts, we will first add sessions. A session is a place to store data, which is persistent for a client on the server. On the client side, a cookie will be saved, which contains an identifier of the session. If a request contains a valid cookie with such an identifier, you will get the same session object. Otherwise, a new session will be created:

import { Server, ServerRequest, ServerResponse, ServerError, StatusCode, SessionStore } from "phaethon"; 
import { ObjectID } from "mongodb"; 
import { User, login, logout } from "./user"; 
import * as note from "./note"; 

Tip

With import { ... }, we can import a set of entities from another file. With import * as ..., we import the whole file as an object. The following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required