Skip to content

Commit

Permalink
Merge pull request #130 from avantifellows/token
Browse files Browse the repository at this point in the history
Auto redirection to destination if the token is valid
  • Loading branch information
suryabulusu authored Aug 27, 2024
2 parents 3302ef8 + b47fe2c commit ad52e77
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_to_s3_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
VITE_APP_BASE_URL_YOUTUBE: "https://www.youtube.com/watch?v="
VITE_APP_CHECK_USER_ENDPOINT: "/checkForUser"
VITE_APP_GET_GROUP_ENDPOINT: "/getGroupData"
VITE_APP_CLOUD_FUNCTIONS_BASE_URL: "https://asia-south1-staging-portal-7df0f.cloudfunctions.net"
VITE_APP_CLOUD_FUNCTIONS_BASE_URL: "https://asia-south1-avantifellows.cloudfunctions.net"
VITE_APP_PORTAL_BACKEND: " https://b93ddkdz0g.execute-api.ap-south-1.amazonaws.com/"
VITE_APP_STUDENT_QUIZ_REPORT_BASE_URL: "https://reports-staging.avantifellows.org/reports/student_quiz_report"
VITE_APP_GURUKUL_BASE_URL: "https://staging-gurukul.avantifellows.org/"
Expand Down
71 changes: 65 additions & 6 deletions src/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ import sessionAPIService from "@/services/API/sessionData.js";
import NoClassMessage from "@/components/NoClassMessage.vue";
import Entry from "@/components/Entry.vue";
import Signup from "@/components/Signup.vue";
import TokenAPI from "@/services/API/token";
import UserAPI from "@/services/API/user.js";
import { redirectToDestination } from "@/services/redirectToDestination";
import { sendSQSMessage } from "@/services/API/sqs";
import useAssets from "@/assets/assets.js";
Expand Down Expand Up @@ -445,11 +449,12 @@ export default {
);
},
},
methods: {
setState() {
this.isLoading = false;
}
},
async created() {
// if (this.platform == "report") {
// this.oldFlow = true;
// }
/**
* If sessionId exists in route, then retrieve session details. Otherwise, fallback to using group data.
*/
Expand Down Expand Up @@ -547,16 +552,70 @@ export default {
});
}
}
if ("input_schema" in this.authGroupData) {
this.$store.dispatch("setLocale", this.authGroupData.input_schema.default_locale);
}
this.isLoading = false;
this.isIdGenerationEnabled;
this.isRedirectionEnabled;
this.setPlatform;
this.setPlatformId;
this.setPlatformLink;
this.setAuthGroupImages;
},
if (!this.oldFlow) {
let [token_verified, user_id] = await TokenAPI.checkForTokens(this.authGroupData.name);
if (token_verified && this.isTypeSignIn) {
await sendSQSMessage(
this.type,
this.sub_type,
this.$store.state.platform,
this.$store.state.platform_id,
user_id,
this.auth_type.toString(),
this.authGroupData.name,
this.authGroupData.input_schema.userType,
this.sessionData &&
"session_id" in this.sessionData
? this.sessionData.session_id
: "",
this.sessionData &&
"meta_data" in this.sessionData &&
"batch" in this.sessionData.meta_data
? this.sessionData.meta_data.batch
: "",
"", //phone number
"",
"" // date of birth
);
if (this.sessionId != "") {
// do not send logs to afdc for reports, gurukul
await UserAPI.postUserSessionActivity(
user_id,
this.$store.state.sessionData.type,
this.$store.state.sessionData.session_id,
this.$store.state.authGroupData.input_schema.user_type,
this.$store.state.sessionData.session_occurrence_id
);
}
redirectToDestination(
this.sub_type,
user_id,
this.$store.state.platform_id,
this.$store.state.platform_link,
this.$store.state.platform,
this.authGroupData.input_schema.userType
);
} else {
this.setState();
}
} else {
this.setState();
}
}
};
</script>
97 changes: 51 additions & 46 deletions src/pages/NewSignin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ import { authToInputParameters } from "@/services/authToInputParameters";
import { validateUser } from "@/services/newValidation.js";
import { redirectToDestination } from "@/services/redirectToDestination";
import { sendSQSMessage } from "@/services/API/sqs";
import { createAccessToken } from "@/services/API/token";
import TokenAPI from "@/services/API/token";
import UserAPI from "@/services/API/user.js";
const assets = useAssets();
Expand Down Expand Up @@ -414,27 +414,31 @@ export default {
} else {
if ("code" in this.userInformation) {
userId = this.userInformation["code"];
createAccessToken(this.userInformation["code"]); // school
}
else if ("teacher_id" in this.userInformation) {
userId = this.userInformation["teacher_id"];
createAccessToken(this.userInformation["teacher_id"]); // teacher
}
else {
userId = this.userInformation["student_id"];
createAccessToken(this.userInformation["student_id"]); // student
}
if (this.enable_popup) {
this.$router.push(`/form/${this.userInformation["student_id"]}`);
UserAPI.postUserSessionActivity(
// create token only for gurukul
if (this.$store.state.platform == "gurukul") {
await TokenAPI.createAccessToken(
userId,
this.$store.state.authGroupData.name
);
}
if (this.enable_pop_up_form) {
await UserAPI.postUserSessionActivity(
this.userInformation["student_id"],
"sign-in",
this.$store.state.sessionData.session_id,
this.$store.state.authGroupData.input_schema.user_type,
this.$store.state.sessionData.session_occurrence_id
);
sendSQSMessage(
await sendSQSMessage(
"sign-in",
this.sub_type,
this.$store.state.platform,
Expand All @@ -453,47 +457,48 @@ export default {
? this.userInformation["date_of_birth"]
: ""
);
this.$router.push(`/form/${this.userInformation["student_id"]}`);
} else {
if (
redirectToDestination(
this.sub_type,
userId,
this.$store.state.platform_id,
this.$store.state.platform_link,
this.$store.state.platform,
this.$store.state.authGroupData.input_schema.user_type
)
) {
UserAPI.postUserSessionActivity(
userId,
this.$store.state.sessionData.type,
this.$store.state.sessionData.session_id,
this.$store.state.authGroupData.input_schema.user_type,
this.$store.state.sessionData.session_occurrence_id
);
sendSQSMessage(
this.$store.state.sessionData.type,
this.sub_type,
this.$store.state.platform,
this.$store.state.platform_id,
userId,
this.auth_type.toString(),
this.$store.state.authGroupData.name,
this.$store.state.authGroupData.input_schema.user_type,
"sessionData" in this.$store.state &&
"session_id" in this.$store.state.sessionData
? this.$store.state.sessionData.session_id
: "",
"",
"phone" in this.userInformation
? this.userInformation["phone"]
: "",
this.getBatch,
"date_of_birth" in this.userInformation
? this.userInformation["date_of_birth"]
: ""
if (this.$store.state.sessionData.session_id != null) {
// do not send logs for reports, gurukul
await UserAPI.postUserSessionActivity(
userId,
this.$store.state.sessionData.type,
this.$store.state.sessionData.session_id,
this.$store.state.authGroupData.input_schema.user_type,
this.$store.state.sessionData.session_occurrence_id
);
}
await sendSQSMessage(
this.$store.state.sessionData.type,
this.sub_type,
this.$store.state.platform,
this.$store.state.platform_id,
userId,
this.auth_type.toString(),
this.$store.state.authGroupData.name,
this.$store.state.authGroupData.input_schema.user_type,
"sessionData" in this.$store.state &&
"session_id" in this.$store.state.sessionData
? this.$store.state.sessionData.session_id
: "",
"",
"phone" in this.userInformation
? this.userInformation["phone"]
: "",
this.getBatch,
"date_of_birth" in this.userInformation
? this.userInformation["date_of_birth"]
: ""
);
redirectToDestination(
this.sub_type,
userId,
this.$store.state.platform_id,
this.$store.state.platform_link,
this.$store.state.platform,
this.$store.state.authGroupData.input_schema.user_type
);
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/services/API/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export const verifyAIETStudentEndpoint = "/checkForAIETStudent";
export const verifyTeacherEndpoint = "/teacher/verify";
export const verifySchoolEndpoint = "/school/verify";
export const createAccessTokenEndpoint = "/auth/create-access-token";
export const verifyTokenEndpoint = "/auth/verify";
export const refreshTokenEndpoint = "/auth/refresh-token";
Loading

0 comments on commit ad52e77

Please sign in to comment.