Skip to content

Commit

Permalink
move sign up to auth service. Test window location href
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogge committed Mar 14, 2024
1 parent 12f8966 commit 85b352f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
45 changes: 25 additions & 20 deletions presenter/src/components/menu/HeaderMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
<div v-if="showAuthentication" class="d-flex align-center mr-0 mr-md-8">
<div v-if="auth.isLoggedIn">
<!--<MainButton
variant="third-inverse"
class="mr-1"
label="Query"
size="small"
@click="queryProtectedBackend"
/>-->
variant="third-inverse"
class="mr-1"
label="Query"
size="small"
@click="queryProtectedBackend"
/>-->
<MainButton
class="sign-out"
variant="third"
Expand Down Expand Up @@ -128,8 +128,13 @@ async function signIn() {
}
}
function signUp() {
window.location.href = AUTH.AUTHORITY_SIGNUP_URI
async function signUp() {
try {
await authService?.signUp()
} catch (error) {
// eslint-disable-next-line no-console
console.log('auth error', error)
}
}
async function signOut() {
Expand All @@ -143,19 +148,19 @@ async function signOut() {
}
/*
const apolloClient = inject<ApolloClient<InMemoryCache>>(DefaultApolloClient)
const apolloClient = inject<ApolloClient<InMemoryCache>>(DefaultApolloClient)
async function queryProtectedBackend() {
try {
const secret = await apolloClient?.query({ query: querySecret })
// eslint-disable-next-line no-console
console.log(secret)
} catch (error) {
// eslint-disable-next-line no-console
console.log('error secret', error)
}
}
*/
async function queryProtectedBackend() {
try {
const secret = await apolloClient?.query({ query: querySecret })
// eslint-disable-next-line no-console
console.log(secret)
} catch (error) {
// eslint-disable-next-line no-console
console.log('error secret', error)
}
}
*/
const appBackground = ref('transparent')
const navBackground = ref('#d8d8d8')
Expand Down
14 changes: 10 additions & 4 deletions presenter/src/services/AuthService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UserManager } from 'oidc-client-ts'
import { describe, it, expect } from 'vitest'

import { AUTH } from '#src/env'
import {
authService,
signinSilentCallbackMock,
signinRedirectMock,
signinCallbackMock,
signoutRedirectMock,
getUserMock,
} from '#tests/mock.authService'

Expand All @@ -25,6 +25,13 @@ describe('AuthService', () => {
})
})

describe('signUp', () => {
it('redirects to signup URI', () => {
authService.signUp()
expect(global.window.location.href).toBe(AUTH.AUTHORITY_SIGNUP_URI)
})
})

describe('signIn', () => {
it('calls signin redirect', async () => {
await authService.signIn()
Expand All @@ -46,11 +53,10 @@ describe('AuthService', () => {
})
})

// how to redirect correctly in vike?
describe('signOut', () => {
it.skip('calls signout redirect', () => {
it('redirects to signout URI', () => {
authService.signOut()
expect(signoutRedirectMock).toBeCalled()
expect(global.window.location.href).toBe(AUTH.AUTHORITY_SIGNOUT_URI)
})
})

Expand Down
4 changes: 4 additions & 0 deletions presenter/src/services/AuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class AuthService {
})
}

public signUp() {
window.location.href = AUTH.AUTHORITY_SIGNUP_URI
}

public signIn() {
return this.userManager.signinRedirect()
}
Expand Down

0 comments on commit 85b352f

Please sign in to comment.