Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/nextjs-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export const withJuno = async (params?: {
}),
...(authClientIds?.google !== undefined && {
[`${prefix}GOOGLE_CLIENT_ID`]: authClientIds.google
}),
...(authClientIds?.github !== undefined && {
[`${prefix}GITHUB_CLIENT_ID`]: authClientIds.github
})
},
...REQUIRED_NEXT_CONFIG
Expand Down
6 changes: 4 additions & 2 deletions plugins/nextjs-plugin/src/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('withJuno', () => {
satelliteId: 'sat-id',
orbiterId: 'orb-id',
authClientIds: {
google: 'google-client-id-123'
google: 'google-client-id-123',
github: 'github-client-id-123'
},
icpIds: {
internetIdentityId: 'ii-id',
Expand Down Expand Up @@ -55,7 +56,8 @@ describe('withJuno', () => {
NEXT_PUBLIC_SNS_WASM_ID: 'sns-wasm-id',
NEXT_PUBLIC_NNS_DAPP_ID: 'nns-dapp-id',
NEXT_PUBLIC_CONTAINER: 'http://localhost:1234',
NEXT_PUBLIC_GOOGLE_CLIENT_ID: 'google-client-id-123'
NEXT_PUBLIC_GOOGLE_CLIENT_ID: 'google-client-id-123',
NEXT_PUBLIC_GITHUB_CLIENT_ID: 'github-client-id-123'
}
});
});
Expand Down
9 changes: 4 additions & 5 deletions plugins/plugin-tools/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ export const authClientIds = async ({mode}: ConfigArgs): Promise<AuthClientIds |
return undefined;
}

const {google} = authentication;
const {google, github} = authentication;

if (google === undefined) {
if (google === undefined && github === undefined) {
return undefined;
}

const {clientId} = google;

return {
google: clientId
...(google?.clientId !== undefined && {google: google.clientId}),
...(github?.clientId !== undefined && {github: github.clientId})
};
};
44 changes: 43 additions & 1 deletion plugins/plugin-tools/src/tests/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ describe('config', () => {
expect(ids).toBeUndefined();
});

it('returns undefined if authentication.google is undefined', async () => {
it('returns undefined if authentication empty object', async () => {
vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true);
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({
satellite: {authentication: {}}
Expand All @@ -469,6 +469,17 @@ describe('config', () => {
expect(ids).toBeUndefined();
});

it('returns undefined if authentication when google and github are undefined', async () => {
vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true);
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({
satellite: {authentication: {github: undefined, google: undefined}}
} as unknown as JunoConfig);

const ids = await authClientIds({params: {}, mode: MODE_DEVELOPMENT});

expect(ids).toBeUndefined();
});

it('returns google clientId when set', async () => {
vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true);
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({
Expand All @@ -483,5 +494,36 @@ describe('config', () => {

expect(ids).toEqual({google: 'google-client-id-123'});
});

it('returns github clientId when set', async () => {
vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true);
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({
satellite: {
authentication: {
github: {clientId: 'github-client-id-123'}
}
}
} as unknown as JunoConfig);

const ids = await authClientIds({params: {}, mode: 'production'});

expect(ids).toEqual({github: 'github-client-id-123'});
});

it('returns google and github clientIds when set', async () => {
vi.spyOn(configLoader, 'junoConfigExist').mockResolvedValue(true);
vi.spyOn(configLoader, 'readJunoConfig').mockResolvedValue({
satellite: {
authentication: {
google: {clientId: 'google-client-id-123'},
github: {clientId: 'github-client-id-123'}
}
}
} as unknown as JunoConfig);

const ids = await authClientIds({params: {}, mode: 'production'});

expect(ids).toEqual({google: 'google-client-id-123', github: 'github-client-id-123'});
});
});
});
8 changes: 7 additions & 1 deletion plugins/plugin-tools/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,11 @@ export interface AuthClientIds {
* Google client ID.
* @type {string}
*/
google: string;
google?: string;

/**
* GitHub client ID.
* @type {string}
*/
github?: string;
}
3 changes: 3 additions & 0 deletions plugins/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export default function Juno(params?: JunoParams): Plugin {
}),
...(authClientIds?.google !== undefined && {
[`${prefix}GOOGLE_CLIENT_ID`]: JSON.stringify(authClientIds.google)
}),
...(authClientIds?.github !== undefined && {
[`${prefix}GITHUB_CLIENT_ID`]: JSON.stringify(authClientIds.github)
})
}
};
Expand Down
6 changes: 4 additions & 2 deletions plugins/vite-plugin/src/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe('vite-plugin-juno', () => {
satelliteId: 'sat-id',
orbiterId: 'orb-id',
authClientIds: {
google: 'google-client-id-123'
google: 'google-client-id-123',
github: 'github-client-id-123'
},
icpIds: {
internetIdentityId: 'ii-id',
Expand Down Expand Up @@ -58,7 +59,8 @@ describe('vite-plugin-juno', () => {
'import.meta.env.VITE_SNS_WASM_ID': JSON.stringify('sns-wasm-id'),
'import.meta.env.VITE_NNS_DAPP_ID': JSON.stringify('nns-dapp-id'),
'import.meta.env.VITE_CONTAINER': JSON.stringify('http://localhost:1234'),
'import.meta.env.VITE_GOOGLE_CLIENT_ID': JSON.stringify('google-client-id-123')
'import.meta.env.VITE_GOOGLE_CLIENT_ID': JSON.stringify('google-client-id-123'),
'import.meta.env.VITE_GITHUB_CLIENT_ID': JSON.stringify('github-client-id-123')
}
});
});
Expand Down