Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
visualjerk committed Jul 28, 2022
0 parents commit 9a0fbdc
Show file tree
Hide file tree
Showing 17 changed files with 5,559 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GITHUB_CLIENT_ID='1234'
GITHUB_CLIENT_SECRET='1234'
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
*.log*
.nuxt
.nitro
.cache
.output
.env
dist
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Nuxt 3 Minimal Starter

Look at the [nuxt 3 documentation](https://v3.nuxtjs.org) to learn more.

## Setup

Make sure to install the dependencies:

```bash
# yarn
yarn install

# npm
npm install

# pnpm
pnpm install --shamefully-hoist
```

## Development Server

Start the development server on http://localhost:3000

```bash
npm run dev
```

## Production

Build the application for production:

```bash
npm run build
```

Locally preview production build:

```bash
npm run preview
```

Checkout the [deployment documentation](https://v3.nuxtjs.org/guide/deploy/presets) for more information.
5 changes: 5 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<h1>Do</h1>
</div>
</template>
26 changes: 26 additions & 0 deletions assets/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@tailwind base;

@layer base {
h1,.h1 {
@apply text-4xl sm:text-5xl text-slate-800 font-bold;
}
h2,.h2 {
@apply text-2xl sm:text-3xl text-slate-800 font-bold;
}
h3,.h3 {
@apply text-xl sm:text-2xl text-slate-800 font-bold;
}
p,.p {
@apply text-lg text-slate-700;
}
p > a,.p > a {
@apply text-teal-600 hover:text-teal-700;
}
}

@tailwind components;
@tailwind utilities;

body {
@apply overflow-y-scroll bg-slate-100;
}
2 changes: 2 additions & 0 deletions constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const GH_COOKIE = 'do_gh_token'
export const USER_STATE = 'user'
15 changes: 15 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineNuxtConfig } from 'nuxt'

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
css: ['@/assets/css/main.css'],
build: {
postcss: {
postcssOptions: require('./postcss.config.cjs'),
},
transpile: ['mdi-vue'],
},
typescript: {
strict: true,
},
})
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview"
},
"devDependencies": {
"@types/luxon": "^3.0.0",
"nuxt": "3.0.0-rc.6",
"tailwindcss": "^3.1.6"
},
"dependencies": {
"luxon": "^3.0.1",
"octokit": "^2.0.4"
}
}
6 changes: 6 additions & 0 deletions postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
34 changes: 34 additions & 0 deletions server/api/auth/callback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { GH_COOKIE } from '@/constants'
import { useQuery, sendRedirect, setCookie } from 'h3'
import { DateTime } from 'luxon'

export default defineEventHandler(async (event) => {
const { code } = useQuery(event)

if (!code) {
return sendRedirect(event, '/')
}
const response: any = await $fetch(
'https://github.com/login/oauth/access_token',
{
method: 'POST',
body: {
client_id: process.env.GITHUB_CLIENT_ID,
client_secret: process.env.GITHUB_CLIENT_SECRET,
code,
},
}
)
if (response.error) {
return sendRedirect(event, '/')
}

setCookie(event, GH_COOKIE, response.access_token, {
path: '/',
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
expires: DateTime.now().plus({ days: 7 }).toJSDate(),
})

return sendRedirect(event, '/')
})
8 changes: 8 additions & 0 deletions server/api/auth/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sendRedirect } from 'h3'

export default defineEventHandler((event) =>
sendRedirect(
event,
`https://github.com/login/oauth/authorize?client_id=${process.env.GITHUB_CLIENT_ID}&scope=user:email`
)
)
12 changes: 12 additions & 0 deletions server/api/auth/logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getCache } from '@/server/cache'
import { GH_COOKIE } from '@/constants'

export default defineEventHandler((event) => {
const ghToken = useCookies(event)[GH_COOKIE]
if (!ghToken) {
return true
}
getCache().del(ghToken)
deleteCookie(event, GH_COOKIE)
return true
})
18 changes: 18 additions & 0 deletions store/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Octokit } from 'octokit'
import { GH_COOKIE } from '@/constants'

let octokit: Octokit | undefined

export async function getApi() {
if (!process.client) {
throw null
}
if (!octokit) {
const ghToken = useCookie(GH_COOKIE)
if (!ghToken) {
return null
}
octokit = new Octokit({ auth: ghToken.value })
}
return octokit
}
33 changes: 33 additions & 0 deletions store/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getApi } from '@/store/api'
import { USER_STATE } from '@/constants'

export async function getUser() {
const api = await getApi()

if (!api) {
return
}
const { data, status } = await api.rest.users.getAuthenticated()

if (status >= 400) {
return
}

const user = useState(USER_STATE)
user.value = {
avatarUrl: data.avatar_url,
}
}

export function login() {
if (!process.client) {
return
}
window.location.pathname = '/api/auth/login'
}

export async function logout() {
await $fetch('/api/auth/logout')
await refreshNuxtData()
useRouter().push('/')
}
16 changes: 16 additions & 0 deletions tailwind.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app.vue',
'./components/**/*.{js,vue,ts}',
'./layouts/**/*.vue',
'./pages/**/*.vue',
'./plugins/**/*.{js,ts}',
'./hooks/**/*.{js,ts}',
'./nuxt.config.{js,ts}',
],
theme: {
extend: {},
},
plugins: [],
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://v3.nuxtjs.org/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
Loading

0 comments on commit 9a0fbdc

Please sign in to comment.