Skip to content

Commit

Permalink
Use const auth key instead of hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Nov 30, 2024
1 parent 9854d60 commit cc79ac2
Show file tree
Hide file tree
Showing 10 changed files with 10,871 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/BottomMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { UserTokenInfo } from '~/server/models/UserTokenInfo';
import { userTokensKey } from '~/server/utils/utils';
const cookie = useCookie('app-auth')
const cookie = useCookie(cookieAuthKey)
const cookiePayload = cookie.value ? decodeJwt(cookie.value) : undefined
const userEmail = cookiePayload?.email?.toString()
const signout = () => {
Expand Down
2 changes: 1 addition & 1 deletion layouts/install-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
</template>

<script setup lang="ts">
const cookie = useCookie('app-auth')
const cookie = useCookie(cookieAuthKey)
</script>
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ definePageMeta({
const route = useRoute()
const router = useRouter()
const cookie = useCookie('app-auth')
const cookie = useCookie(cookieAuthKey)
const isLoggedIn = computed(() => cookie.value ? true : false)
if (isLoggedIn.value) {
if (process.client) {
Expand Down
2 changes: 1 addition & 1 deletion pages/install/[publicId]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ useSeoMeta({
const { download, isDownloading } = useDownloadArtifact(appName.toString(), orgName.toString())
const cookie = useCookie('app-auth')
const cookie = useCookie(cookieAuthKey)
</script>

<style scoped>
Expand Down
2 changes: 1 addition & 1 deletion pages/signin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const route = useRoute()
const isAddAccount = computed(() => route.path.startsWith('/add-account'))
if (!isAddAccount.value) {
const cookie = useCookie('app-auth')
const cookie = useCookie(cookieAuthKey)
if (cookie.value) {
await navigateTo({
name: 'index',
Expand Down
2 changes: 1 addition & 1 deletion server/api/auth/sign-in-google.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const generateUserToken = async (
export const signInUser = (
event: H3Event<EventHandlerRequest>,
token: string) => {
setCookie(event, 'app-auth', token, {
setCookie(event, cookieAuthKey, token, {
httpOnly: false,
secure: true,
sameSite: 'lax',
Expand Down
6 changes: 3 additions & 3 deletions server/middleware/auth-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export default defineEventHandler(async (event) => {
if (event.path === '/healthcheck') {
return
}
const appAuth = getCookie(event, 'app-auth')
const appAuth = getCookie(event, cookieAuthKey)
if (appAuth) {
try {
const verifiedData = await jose.jwtVerify(appAuth, getJwtKey(event))
if (!verifiedData) {
deleteCookie(event, 'app-auth')
deleteCookie(event, cookieAuthKey)
} else {
const userId = verifiedData.payload.sub
const email = verifiedData.payload.email as string | undefined
Expand All @@ -34,7 +34,7 @@ export default defineEventHandler(async (event) => {
}
catch (e) {
console.log(e)
deleteCookie(event, 'app-auth')
deleteCookie(event, cookieAuthKey)
}
} else {
console.log('user not logged in')
Expand Down
2 changes: 2 additions & 0 deletions server/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ export const singleOrDefault = <T extends any[]>(values: T): T[number] | undefin
}

export { z } from "zod";

export const cookieAuthKey = 'app-auth'
2 changes: 1 addition & 1 deletion tests-e2e/setup/auth.setup.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const authFile = path.join(import.meta.dirname, '../../playwright/.auth/user.jso
setup('authenticate', async ({ page }) => {
const domain = process.env.TEST_APP_URL!.replaceAll('https://', '').replaceAll('http://', '').replaceAll(':3000', '')
await page.context().addCookies([{
name: 'app-auth',
name: cookieAuthKey,
value: process.env.TEST_APP_AUTH_COOKIES!,
httpOnly: false,
secure: true,
Expand Down
Loading

0 comments on commit cc79ac2

Please sign in to comment.