My VSCode setup is heavily inspired, and some parts even exclusively come from glennraya, especially the custom CSS and JS. He also has a YouTube video where he walks through what's what if you're interested.
Required Extensions
Font
| // config/auth.ts | |
| import { defineConfig } from '@adonisjs/auth' | |
| import { sessionGuard, sessionUserProvider } from '@adonisjs/auth/session' | |
| import type { | |
| InferAuthEvents, | |
| Authenticators as AuthenticatorEvents, | |
| InferAuthenticators, | |
| } from '@adonisjs/auth/types' | |
| import { tokensGuard, tokensUserProvider } from '@adonisjs/auth/access_tokens' |
My VSCode setup is heavily inspired, and some parts even exclusively come from glennraya, especially the custom CSS and JS. He also has a YouTube video where he walks through what's what if you're interested.
Required Extensions
Font
| export const movies = [{ | |
| title: "3:10 to Yuma", | |
| releaseYear: 1957 | |
| }, { | |
| title: "The 7th Voyage of Sinbad", | |
| releaseYear: 1958 | |
| }, { | |
| title: "12 Angry Men", | |
| releaseYear: 1957 | |
| }, { |
| { | |
| "editor.fontFamily": "'Operator Mono Light','Dank Mono','Cascadia Code Light', Menlo, Monaco, 'Courier New', monospace", | |
| "workbench.colorTheme": "GitHub Blue", | |
| "editor.inlineSuggest.enabled": true, | |
| "workbench.iconTheme": "minimal-icons-without-explorer-arrows", | |
| "editor.tabSize": 2, | |
| "workbench.statusBar.visible": false, | |
| "workbench.fontAliasing": "auto", | |
| "workbench.tips.enabled": false, | |
| "breadcrumbs.enabled": false, |
| export default class ExampleController { | |
| public async index({ request, response }: HttpContextContract) { | |
| const data = await request.validate(ExampleValidator); | |
| const domain = psl.get(data.host); | |
| const agent = request.headers()['user-agent'] || data.agent; | |
| const { browser, browserVersion, os } = PlatformService.parse(agent); | |
| // ... | |
| } | |
| } |
| import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | |
| export default class Guest { | |
| public async handle({ auth, response }: HttpContextContract, next: () => Promise<void>) { | |
| if (auth.user) { | |
| // redirect user where ever you'd like | |
| return response.redirect('/'); | |
| } | |
| await next() |
| /* | |
| * This middleware will take in a user relation to check against. | |
| * It will then check: | |
| * 1. Is there an authenticated user? If not, Unauthorized access is thrown | |
| * 2. It'll then check if the authenticated user is either an admin or the record owner. If not, Access denied is thrown | |
| * | |
| * Ownership here is enforced by query off the authenticated user's relationships | |
| */ | |
| import { AuthenticationException } from '@adonisjs/auth/build/standalone' |
| public async register({ request, response, auth, session }: HttpContextContract) { | |
| const validationSchema = schema.create({ | |
| username: schema.string({ trim: true }, [ | |
| rules.maxLength(50), | |
| rules.minLength(3), | |
| rules.unique({ table: 'users', column: 'username' }), | |
| rules.regex(/^[a-zA-Z0-9-_]+$/), | |
| rules.notIn(['admin', 'super', 'power', 'jagr', 'jagrco', '_jagr', '_jagrco', 'jagr_', 'jagrco_', 'jagr-co', 'moderator', 'public', 'dev', 'alpha', 'mail']) | |
| ]), | |
| email: schema.string({ trim: true }, [rules.unique({ table: 'users', column: 'email' })]), |
| export default { | |
| // Disable server-side rendering (https://go.nuxtjs.dev/ssr-mode) | |
| ssr: false, | |
| // Global page headers (https://go.nuxtjs.dev/config-head) | |
| head: { | |
| title: 'throwaway', | |
| meta: [ | |
| { charset: 'utf-8' }, | |
| { name: 'viewport', content: 'width=device-width, initial-scale=1' }, |
| async signUp({ username, password, email }) { | |
| try { | |
| const user = await Auth.signUp({ | |
| username, | |
| password, | |
| attributes: { | |
| }, | |
| validationData: [] | |
| }); |