Skip to content

Commit

Permalink
fix localhost (#7)
Browse files Browse the repository at this point in the history
* fix localhost

Signed-off-by: Jess Frazelle <[email protected]>

* upfates

Signed-off-by: Jess Frazelle <[email protected]>

* updates

Signed-off-by: Jess Frazelle <[email protected]>

* fmt

Signed-off-by: Jess Frazelle <[email protected]>

---------

Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz authored Oct 18, 2023
1 parent b9d0bfd commit 6bf3239
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 18 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ Please run the following commands to ensure that your code is as ready for revie
```bash
yarn fmt --fix && yarn test
```

### Setting a cookie for local host

1. Get a dev api token from: https://dev.kittycad.io
2. Open the dev console and run the following:

```js
var CookieDate = new Date()
CookieDate.setFullYear(CookieDate.getFullYear() + 10)
document.cookie =
'__Secure-next-auth.session-token=YOUR_TOKEN;Secure;expires=' + CookieDate.toUTCString() + ';'
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vite-plugin-mkcert": "^1.16.0",
"vitest": "^0.32.2"
},
"type": "module",
Expand Down
6 changes: 5 additions & 1 deletion src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { users, Client } from '@kittycad/lib'
/** @type {import('./$types').LayoutData} */
export const load = async ({ cookies }) => {
const token = cookies.get('__Secure-next-auth.session-token')
console.log('token', token)
if (!token) {
return {
user: undefined
}
}

const client = new Client(token || '')
const response = await users.get_user_self({ client })
Expand Down
17 changes: 14 additions & 3 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import type { Actions } from './$types'

type LoadResponse = {
status: number
body: ListResponse
body?: ListResponse
}

type SubmissionResponse = {
status: number
body: PromptResponse
body?: PromptResponse
}

export const load = async ({ cookies }) => {
const token = cookies.get('__Secure-next-auth.session-token')
console.log('token', token)

if (!token) {
return {
status: 401
} satisfies LoadResponse
}

const response = await fetch(endpoints.list({ limit: 10 }), {
headers: {
Expand All @@ -32,6 +37,12 @@ export const load = async ({ cookies }) => {
export const actions = {
default: async (event) => {
const token = event.cookies.get('__Secure-next-auth.session-token')

if (!token) {
return {
status: 401
} satisfies SubmissionResponse
}
const formData = await event.request.formData()
// TODO make a call to the prompt API

Expand Down
40 changes: 27 additions & 13 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig } from 'vitest/config'
import { defineConfig, loadEnv } from 'vite'
import mkcert from 'vite-plugin-mkcert'

export default defineConfig({
plugins: [sveltekit()],
server: {
port: 3000,
strictPort: true
},
preview: {
port: 3000,
strictPort: true
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
loadEnv(mode, process.cwd(), '')

const plugins = [sveltekit()]
if (mode === 'development') {
plugins.push(mkcert())
}

return {
plugins,
server: {
port: 3000,
strictPort: true,
https: mode === 'development'
},
preview: {
port: 3000,
strictPort: true,
https: mode === 'development'
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
}
}
})
Loading

0 comments on commit 6bf3239

Please sign in to comment.