Skip to content

Instantly share code, notes, and snippets.

[[redirects]]
from = "/*"
to = "/index.html"
status = 200
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@service foo;
@action
@iamdtang
iamdtang / components.glimmer-component\.js
Created June 27, 2020 18:01
modifiers-with-curly-invocation
import Component from '@glimmer/component';
export default class extends Component {
}
@iamdtang
iamdtang / overview.md
Last active April 28, 2020 03:03
Token-based Authentication for SPAs Overview

Token-based Authentication for SPAs Overview

When a client logs in, issue them a JWT with an expiration (more on this below). On subsequent API requests, send that token in an Authorization header as a Bearer token. This token can be stored in localStorage, which is the most common, so that if the user revisits the site or refreshes the page, they are still logged in. Other client-side storage options like sessionStorage or a cookie can be used. JWTs can get big though depending on how much information is stored in the payload, which could exceed the maximum cookie size (4K).

How do I handle token expiration?

When an API call is made with an expired token, return a 401 HTTP status code and redirect users to the login page.

What if I don't want to disrupt the UX and force users to reauthenticate?

@iamdtang
iamdtang / overview.md
Last active April 27, 2020 06:33
Hashing, Encryption, Digital Signatures

Hashing

You want to store something securely and don't care about getting the original value back (like passwords).

Hash::make($request->input('password')); // $2y$10$Kk0JK7CZ2rMFVf.uMysZHu2U4/7B4/XjydFJrs5ayiFMvyMWJyF2W

Encryption

@iamdtang
iamdtang / user-profile.ts
Last active December 29, 2019 01:08
TypeScript example with Ember Octane
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';
import User from 'my-app/models/user';
import Technology from 'my-app/models/technology';
import TimeZone from 'my-app/models/time-zone';
import { inject as service } from '@ember/service';
import DS from 'ember-data';
import ApplicationInstance from '@ember/application/instance';
@iamdtang
iamdtang / index.js
Last active February 11, 2019 23:07
console.log('sup');
@iamdtang
iamdtang / Genre.php
Last active February 5, 2019 08:29
Laravel Eloquent relationship examples based on http://www.sqlitetutorial.net/sqlite-sample-database/
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Genre extends Model
{
protected $primaryKey = 'GenreId';

1. Find all playlists

// app/Playlist.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Playlist extends Model
const express = require('express');
const knex = require('knex');
const app = express();
const port = process.env.PORT || 8000;
app.get('/api/genres', function(request, response) {
let knex = connect();
knex.select().from('genres').then((genres) => {
response.json(genres);
});