-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
771 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/pb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<script setup lang="ts"> | ||
import {RouterView} from 'vue-router' | ||
import {useAuthStore} from "@/stores/auth"; | ||
import { RouterView } from 'vue-router' | ||
import { useAuthStore } from '@/stores/auth' | ||
import Dashboard from '@/components/Dashboard.vue' | ||
const authStore = useAuthStore(); | ||
const authStore = useAuthStore() | ||
</script> | ||
|
||
<template> | ||
<Dashboard v-if="authStore.accessToken"/> | ||
<RouterView v-else/> | ||
<Dashboard v-if="authStore.accessToken" /> | ||
<RouterView v-else /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import {createConnectTransport} from "@connectrpc/connect-web"; | ||
import {createClient} from "@connectrpc/connect"; | ||
import {AuthService} from "@/pb/api/v1/auth_connect"; | ||
import {ExerciseService} from "@/pb/api/v1/exercise_connect"; | ||
import {auth, logger} from "@/clients/interceptors"; | ||
import {RoutineService} from "@/pb/api/v1/routines_connect"; | ||
import { createConnectTransport } from '@connectrpc/connect-web' | ||
import { createClient } from '@connectrpc/connect' | ||
import { AuthService } from '@/pb/api/v1/auth_connect' | ||
import { ExerciseService } from '@/pb/api/v1/exercise_connect' | ||
import { auth, logger } from '@/clients/interceptors' | ||
import { RoutineService } from '@/pb/api/v1/routines_connect' | ||
|
||
const transport = createConnectTransport({ | ||
baseUrl: import.meta.env.VITE_API_URL, | ||
fetch: (url, options) => { | ||
// TODO: Include credentials only on refresh token and logout requests. | ||
return fetch(url, {...options, credentials: 'include'}); // Add credentials | ||
return fetch(url, { ...options, credentials: 'include' }) // Add credentials | ||
}, | ||
interceptors: [logger, auth], | ||
}); | ||
}) | ||
|
||
export const AuthClient = createClient(AuthService, transport); | ||
export const ExerciseClient = createClient(ExerciseService, transport); | ||
export const RoutineClient = createClient(RoutineService, transport); | ||
export const AuthClient = createClient(AuthService, transport) | ||
export const ExerciseClient = createClient(ExerciseService, transport) | ||
export const RoutineClient = createClient(RoutineService, transport) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import type {Interceptor} from "@connectrpc/connect"; | ||
import {useAuthStore} from "@/stores/auth"; | ||
import {Code, ConnectError} from "@connectrpc/connect"; | ||
import {RefreshAccessTokenOrLogout} from "@/jwt/jwt"; | ||
import type { Interceptor } from '@connectrpc/connect' | ||
import { useAuthStore } from '@/stores/auth' | ||
import { Code, ConnectError } from '@connectrpc/connect' | ||
import { RefreshAccessTokenOrLogout } from '@/jwt/jwt' | ||
|
||
export const logger: Interceptor = (next) => async (req) => { | ||
console.log(`sending message to ${req.url}`); | ||
return next(req); | ||
}; | ||
console.log(`sending message to ${req.url}`) | ||
return next(req) | ||
} | ||
|
||
export const auth: Interceptor = (next) => async (req) => { | ||
const authStore = useAuthStore(); | ||
const authStore = useAuthStore() | ||
try { | ||
req.header.set("Authorization", `Bearer ${authStore.accessToken}`); | ||
return next(req); | ||
req.header.set('Authorization', `Bearer ${authStore.accessToken}`) | ||
return next(req) | ||
} catch (error) { | ||
if (!(error instanceof ConnectError)) { | ||
throw error; | ||
throw error | ||
} | ||
|
||
if (error.code !== Code.Unauthenticated) { | ||
throw error; | ||
throw error | ||
} | ||
|
||
console.log("refreshing access token to attempt request again"); | ||
await RefreshAccessTokenOrLogout(); | ||
req.header.set("Authorization", `Bearer ${authStore.accessToken}`); | ||
return next(req); | ||
console.log('refreshing access token to attempt request again') | ||
await RefreshAccessTokenOrLogout() | ||
req.header.set('Authorization', `Bearer ${authStore.accessToken}`) | ||
return next(req) | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
<script setup lang="ts"> | ||
const props = defineProps<{ | ||
name: string, | ||
label?: string, | ||
name: string | ||
label?: string | ||
sets: Array<{ | ||
reps: number, | ||
weight: number, | ||
reps: number | ||
weight: number | ||
}> | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<p> | ||
<span class="font-semibold mr-1">{{ props.name }}</span> | ||
<span class="bg-indigo-600 text-white text-xs rounded py-0.5 px-1" v-if="props.label">{{ props.label }}</span> | ||
<span class="bg-indigo-600 text-white text-xs rounded py-0.5 px-1" v-if="props.label">{{ | ||
props.label | ||
}}</span> | ||
</p> | ||
<p class="mb-2"> | ||
<span class="mr-2" v-for="(set, index) in props.sets" :key="index">{{ set.weight }} kg x {{ set.reps }}</span> | ||
<span class="mr-2" v-for="(set, index) in props.sets" :key="index" | ||
>{{ set.weight }} kg x {{ set.reps }}</span | ||
> | ||
</p> | ||
</template> | ||
|
||
<style scoped> | ||
</style> | ||
<style scoped></style> |
Oops, something went wrong.