Skip to content

Instantly share code, notes, and snippets.

@nickradford
nickradford / middleware.ts
Created December 13, 2022 22:30
Next.js 13 middleware example
/*
Say you have an app with an admin interface served at /app/admin, and you only want logged in users
who are also admins to be able to access those routes, otherwise redirect the user to /app.
You could handle this with getServerSideProps on each individual page, but its simpler to do it at the
middleware level.
*/
// Must export a function named middleware, but I think it will also take the default exported function
export async function middleware(req: NextRequest, res: NextResponse) {

Keybase proof

I hereby claim:

  • I am nickradford on github.
  • I am nickradford (https://keybase.io/nickradford) on keybase.
  • I have a public key ASBXgg_IG308q2eNw04oDKabKq6_SxvnDx2bCvt4-ojD2go

To claim this, I am signing this object:

@nickradford
nickradford / decorators.js
Last active October 9, 2015 05:38
ES7 Decorators
function get(target, key, descriptor) {
target[key].__method = 'GET' // Cannot set property '__method' of undefined
return descriptor
}
class User {
@get
static findOne() {}
}
@nickradford
nickradford / es7-function-binding.es7.js
Last active October 5, 2015 21:22
An exploration into ES7 function binding.
function map(cb = identity) {
let ref = []
for (let i in this) {
ref.push(cb(this[i]))
}
return ref
}
@nickradford
nickradford / SassMeister-input-HTML.haml
Created October 27, 2014 14:36
Generated by SassMeister.com.
.button Button
.button-primary Primary
.button-error Error
.button-success Success
%button.button Button
%a.button-primary Yay
➜ ionic-test ionic build ios
add to body class: platform-ios
Running command: /Users/nickradford/code/ionic-test/platforms/ios/cordova/build
Build settings from command line:
ARCHS = i386
CONFIGURATION_BUILD_DIR = /Users/nickradford/code/ionic-test/platforms/ios/build/emulator
SDKROOT = iphonesimulator7.1
VALID_ARCHS = i386
=== BUILD TARGET CordovaLib OF PROJECT CordovaLib WITH CONFIGURATION Debug ===
@nickradford
nickradford / SassMeister-input-HTML.html
Created September 3, 2014 20:34
Generated by SassMeister.com.
<h2>Underline</h2>
<p>Utility class</p>
<pre><code>.u-underline {
text-decoration: underline;
}</code></pre>
<p class='u-underline'>This text is underlined</p>
<hr>
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<polymer-element name="x-card">
<template>
<style>
:host {
position: absolute;
width: 100%;
capabilities: {
browserName: 'chrome',
platform: 'OS X 10.8',
version: '31',
'screen-resolution': '1280x1024'
}
capabilities: {
browserName: 'chrome',
platform: 'OS X 10.8',
version: '31',
'screen-resolution': '1280x1024'
}