Skip to content

Commit

Permalink
added complete oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Moneexa committed Nov 19, 2023
1 parent b27522e commit 2a72223
Show file tree
Hide file tree
Showing 10 changed files with 1,513 additions and 299 deletions.
1,151 changes: 1,134 additions & 17 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
"format": "prettier --write . --ignore-unknown"
},
"dependencies": {
"@auth0/auth0-spa-js": "^2.1.2",
"@mdi/font": "^7.2.96",
"@octokit/rest": "^20.0.2",
"antlr4": "^4.13.0",
"axios": "^1.4.0",
"core-js": "^3.31.1",
"firebase": "^10.6.0",
"marked": "^5.1.1",
"pizzly-js": "^0.2.8",
"roboto-fontface": "*",
Expand Down
58 changes: 35 additions & 23 deletions src/components/ConnectToGitHubButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
</template>

<script>
import Pizzly from "pizzly-js";
import config from "../config";
import { signInWithPopup, GithubAuthProvider } from "firebase/auth";
import { auth, GithubProvider } from "../plugins/firebase/client";
export default {
name: "connectGitHub",
Expand All @@ -16,41 +17,52 @@ export default {
repositories: []
}),
mounted() {
// Here we initialize Pizzly.
console.log("mounted");
this.$pizzly = new Pizzly({
host: config.pizzlyHost,
publishableKey: config.pizzlyPublishableKey
});
},
destroyed() {
console.log("Bye from the git login github component!");
},
methods: {
hasAuthId() {
if (localStorage.getItem("authId") === null) {
this.connect();
} else
this.signInWithGithub()
} else {
this.$router.push({
name: "Editor",
params: { id: this.user }
});
}
},
connect: function () {
// Here, we create a new method
// that "connect" a user to GitHub
this.$pizzly.integration("github").connect().then(this.connectSuccess).catch(this.connectError);
},
connectSuccess: function (data) {
// On success, we update the user object
this.user = data.authId;
localStorage.setItem("authId", data.authId);
this.$router.push({ name: "Editor", params: { id: this.user } });
},
connectError: function (err) {
console.log("error");
console.error(err);
//LOGIN WITH GITHUB
signInWithGithub: async function () {
GithubProvider.addScope('repo read:user gist workflow read:org')
return signInWithPopup(auth, GithubProvider)
.then((result) => {
const credential = GithubAuthProvider.credentialFromResult(result);
const token = credential.accessToken; //Token OAuth (JWT)
const user = result.user
localStorage.setItem("authId", token)
localStorage.setItem('user', user?.reloadUserInfo?.screenName)
// getGithubProfile(token).then(userProfile => console.log('Github Profile', userProfile))
// console.log('Authenticated User', user)
this.$router.push({
name: "Editor",
params: { id: this.user }
});
}).catch((error) => {
console.error('SignIn Error', error)
});
}
}
};
</script>
91 changes: 26 additions & 65 deletions src/components/DialogAddRepositories.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<template>
<v-dialog
v-bind:value="showDialog"
v-on:input="
(value) => {
showDialog = value;
$emit('input', value);
}
"
width="700"
:fullscreen="$vuetify.breakpoint.mobile"
scrollable
>
<v-dialog v-bind:value="showDialog" v-on:input="(value) => {
showDialog = value;
$emit('input', value);
}
" width="700" :fullscreen="$vuetify.breakpoint.mobile" scrollable>
<template v-slot:activator="{ on, attrs }">
<slot name="activator" v-bind:on="on" v-bind:attrs="attrs"> </slot>
<v-overlay data-cy="loadReposBool" :value="showLoadingOverlay">
Expand All @@ -26,26 +19,14 @@
</v-avatar>
<span class="dialogTitle"> Add Repositories </span>
</div>
<v-text-field
data-cy="search-field-for-adding-repository"
v-model="searchText"
class="pl-8 pr-4 pt-0 mt-0"
hide-details
clearable
append-icon="mdi-magnify"
placeholder="Search..."
@input="searchRepositories"
@click:clear="
<v-text-field data-cy="search-field-for-adding-repository" v-model="searchText"
class="pl-8 pr-4 pt-0 mt-0" hide-details clearable append-icon="mdi-magnify" placeholder="Search..."
@input="searchRepositories" @click:clear="
searchText = '';
loadRepositoryList();
"
/>
<v-progress-linear
:active="countLoadingPromises > 0"
:indeterminate="countLoadingPromises > 0"
absolute
top
/>
loadRepositoryList();
" />
<v-progress-linear :active="countLoadingPromises > 0" :indeterminate="countLoadingPromises > 0" absolute
top />
</v-row>
</v-card-title>

Expand All @@ -60,22 +41,13 @@

<!-- Unstaged Repositories -->
<v-card-text class="my-0">
<div
data-cy="noRepo"
v-if="unstagedRepositories.length === 0 && countLoadingPromises === 0"
class="text-center"
>
<div data-cy="noRepo" v-if="unstagedRepositories.length === 0 && countLoadingPromises === 0"
class="text-center">
Sorry, no repositories were found!
</div>
<v-list>
<v-list-item
data-cy="listRepo"
v-for="(item, index) in unstagedRepositories"
class="my-0 py-0"
:key="`item-${index}`"
:value="item"
@click="stageRepostiory(item)"
>
<v-list-item data-cy="listRepo" v-for="(item, index) in unstagedRepositories" class="my-0 py-0"
:key="`item-${index}`" :value="item" @click="stageRepostiory(item)">
<v-list-item-content class="my-0 py-0">
<v-list-item-title class="d-flex">
{{ item.name }} <v-spacer></v-spacer>
Expand All @@ -96,13 +68,8 @@
<v-card-title>Repositories to be added</v-card-title>
<v-card-text class="my-0 flex-grow-0 flex-shrink-0" :style="{ 'max-height': '25%' }">
<v-list>
<v-list-item
v-for="(item, index) in repositoriesSelected"
class="my-0 py-0"
:key="`item-${index}`"
:value="item"
@click="unstageRepostiory(item)"
>
<v-list-item v-for="(item, index) in repositoriesSelected" class="my-0 py-0" :key="`item-${index}`"
:value="item" @click="unstageRepostiory(item)">
<v-list-item-content class="my-0 py-0">
<v-list-item-title v-text="item.name"></v-list-item-title>
<v-list-item-subtitle v-text="item.description"></v-list-item-subtitle>
Expand All @@ -117,18 +84,11 @@
<v-divider></v-divider>
<v-card-actions class="buttonPadding">
<v-spacer></v-spacer>
<v-btn
data-cy="addRepoDialog"
text
color="success"
:disabled="repositoriesSelected.length === 0"
@click="
() => {
showDialog = false;
addRepositories();
}
"
>
<v-btn data-cy="addRepoDialog" text color="success" :disabled="repositoriesSelected.length === 0" @click="() => {
showDialog = false;
addRepositories();
}
">
Add Repositories
</v-btn>
<v-btn text color="error" @click="showDialog = false"> Cancel </v-btn>
Expand Down Expand Up @@ -207,9 +167,9 @@ export default {
/**
* Loads all (added and unadded) repositories the user is authorized to access into repositoriesCurrentPage.
*/
loadRepositoryList() {
async loadRepositoryList() {
this.countLoadingPromises++;
loadRepositoryList(this.searchText, this.page, this.perPage)
loadRepositoryList()
.then((res) => {
if (!Array.isArray(res)) {
throw "Could not load repository list.";
Expand Down Expand Up @@ -240,6 +200,7 @@ export default {
searchRepositoryList(this.searchText, this.perPage, this.repositoriesCurrentPage)
.then((repos) => {
console.log("Loaded Repos", repos);
if (!Array.isArray(repos)) {
throw "Could not search repository list.";
}
Expand Down
Loading

0 comments on commit 2a72223

Please sign in to comment.