<commit_before>// TODO typing!
var Hapi = require("hapi");
var jwt = require("jsonwebtoken");
var tokenAuth = require("hapi-auth-jwd");

var server = new Hapi.Server();

server.connection({ port: 3001 });

var accounts = {
    123: {
        id: 123,
        user: 'john',
        fullName: '<NAME>',
        scope: ['a', 'b']
    }
};

// Use this token to build your request with the 'Authorization' header.
// Ex:
//     Authorization: Bearer <token>
var token = jwt.sign({ accountId: 123 }, privateKey);

const validate = (decodeToken: any, callback: Function) => {
    var error: string = undefined;
    var credentials = accounts[decodeToken.accountId] || { };

    if (!credentials) {
        // USER NOT FOUND
        console.log("User not found!");
        return callback(error, false, credentials);
    }

    console.log("User found");
    return callback(error, true, credentials);
};

var privateKey = "<KEY>";

server.register(tokenAuth, (error: any) => {
    server.auth.strategy("token", "jwt", {
        key: privateKey,
        validateFunc: validate
    });

    server.route({
        method: "GET",
        path: "/",
        config: {
            auth: "token"
        }<commit_msg>Fixed typing issue on tokenizer.<commit_after>// TODO typing!
var Hapi = require("hapi");
var jwt = require("jsonwebtoken");
var tokenAuth = require("hapi-auth-jwd");

var server = new Hapi.Server();

server.connection({ port: 3001 });

var accounts = {
    123: {
        id: 123,
        user: 'john',
        fullName: '<NAME>',
        scope: ['a', 'b']
    }
};

// Use this token to build your request with the 'Authorization' header.
// Ex:
//     Authorization: Bearer <token>
var token = jwt.sign({ accountId: 123 }, privateKey);

const validate = (decodeToken: any, callback: Function) => {
    var error: string = undefined;
    var credentials = (<any>accounts)[<any>decodeToken.accountId] || { };

    if (!credentials) {
        // USER NOT FOUND
        console.log("User not found!");
        return callback(error, false, credentials);
    }

    console.log("User found");
    return callback(error, true, credentials);
};

var privateKey = "<KEY>";

server.register(tokenAuth, (error: any) => {
    server.auth.strategy("token", "jwt", {
        key: privateKey,
        validateFunc: validate
    });

    server.route({
        method: "GET",
        path: "/",
        config: {
            auth: "token"
        }
{'fraction_non_alphanumeric': 0.15772224498156492, 'fraction_numerical': 0.010651372388365424, 'mean_word_length': 2.623145400593472, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4847317', 'n_tokens_mistral': 768, 'n_tokens_neox': 739, 'n_words': 208}